|
dougdrums posted:BSON is kinda silly. Auditing mongoDB databases is fun (because you can charge more). My DB class in college was 90% mongoDB and also 100% a waste of time. wait you learned about mongodb in college? that technology has a learning curve of about an hour. what did you do for the rest of the semester?
|
# ? Nov 24, 2018 07:50 |
|
|
# ? May 14, 2024 16:45 |
|
Oh yeah my thoughts exactly. It was more of a mac troubleshooting class, not unlike the others. Relational algebra got a week.
|
# ? Nov 25, 2018 02:57 |
|
I just spent days writing a bunch of github wiki pages. I think I might have praised this thing before, but the Markdown Navigator plugin for PyCharm (well any Jetbrains product I think) is pretty frickin great for writing markdown documents. It has a bit of a learning curve to get past the basics, but it's neato. edit: I just remembered that I've posted about this before. oops Thermopyle fucked around with this message at 17:42 on Nov 27, 2018 |
# ? Nov 26, 2018 19:11 |
|
Wallet posted:The best way to store a date? Clearly a string, except when you feel like using an ISODate. Want to record whether something is supposed to be on or off? Use a string and set the value to "on" or "off", obviously. To be fair, I've seen both of these crimes committed in RDBMSs, too.
|
# ? Nov 27, 2018 15:33 |
|
I have an easy one thats frustrating me. I want to replace a bunch of strings inside df['col1'][i] with values from df['col2'][i] I have a column in a dataframe df_maps called name with strings in it: Bob Dan Sean Another called param1 A B C I have a column called 'html' with some html in it and stuff to replace ($name and $param1) <h2>$name</h2><span style="color: #008000;"><strong>$param1</strong> This executes: code:
<h2>$name</h2><span style="color: #008000;"><strong>$param1</strong> instead of <h2>Dan</h2><span style="color: #008000;"><strong>$param1</strong>
|
# ? Nov 27, 2018 21:02 |
|
You are re-creating the column 'combined' at every iteration of the loop, essentially resetting it. Try this:Python code:
Python code:
SurgicalOntologist fucked around with this message at 21:19 on Nov 27, 2018 |
# ? Nov 27, 2018 21:16 |
|
SurgicalOntologist posted:You are re-creating the column 'combined' at every iteration of the loop, essentially resetting it. Try this: I feel like an idiot and that worked.
|
# ? Nov 27, 2018 21:21 |
|
I'm trying to have mypy check my type hints, and..I think I've no idea what I'm doing. This runs fine: Python code:
code:
e: another troublesome one: Python code:
code:
unpacked robinhood fucked around with this message at 15:12 on Nov 28, 2018 |
# ? Nov 28, 2018 14:04 |
First example works just fine for me with strict mypy, so I'm confused what are you doing there. What Python and mypy versions are you using?Python code:
Second example is not sufficient - what are you typing and how? cinci zoo sniper fucked around with this message at 15:50 on Nov 28, 2018 |
|
# ? Nov 28, 2018 15:47 |
|
Another viable alternative for pos += users is pos.extend(users). They're mostly the same thing.
|
# ? Nov 28, 2018 17:11 |
|
cinci zoo sniper posted:First example works just fine for me with strict mypy, so I'm confused what are you doing there. What Python and mypy versions are you using? cinci zoo sniper posted:Also you should replace that for block with pos += users, or pos += [....] alltogether. I should have included the function signature in my second question: Python code:
yep unpacked robinhood fucked around with this message at 17:35 on Nov 28, 2018 |
# ? Nov 28, 2018 17:23 |
unpacked robinhood posted:That's python 3.7 and mypy 0.641 This makes literally 0 sense, to be fully honest with you, since that doesn't change anything from type perspective. unpacked robinhood posted:I should have included the function signature in my second question: How does a_list relates to jslog, and how does function return relate to a_list? Looking at what you show I also don't see where would Union[int, slice] enter the scene altogether. cinci zoo sniper fucked around with this message at 17:45 on Nov 28, 2018 |
|
# ? Nov 28, 2018 17:39 |
|
Thanks. I've been trying to replicate my issue on a short standalone example but so far it won't not work. My question probably can't really be answered without seeing the complete function, which i'm not comfortable posting atm.
|
# ? Nov 28, 2018 18:56 |
|
unpacked robinhood posted:I'm trying to have mypy check my type hints, and..I think I've no idea what I'm doing. The first error makes it look like you used lt earlier in your function with a different type. If that's the case it also explains why it's inferring lt as a List in the second error. quote:e: another troublesome one: This could be a similar issue where mypy thinks the type for another_list is List[str]. Don't forget about using reveal_type to show what mypy thinks variables are, it can be really useful!
|
# ? Nov 28, 2018 19:45 |
|
This discussion is reminding me that I hate lambda and how it always makes code look super ugly. Does anyone else hate lambda?
|
# ? Nov 29, 2018 01:22 |
|
QuarkJets posted:This discussion is reminding me that I hate lambda and how it always makes code look super ugly. Does anyone else hate lambda? Yes. It's yucky.
|
# ? Nov 29, 2018 01:45 |
|
QuarkJets posted:This discussion is reminding me that I hate lambda and how it always makes code look super ugly. Does anyone else hate lambda? For example, this above: Python code:
JavaScript code:
Rust code:
Python code:
Dominoes fucked around with this message at 04:12 on Nov 29, 2018 |
# ? Nov 29, 2018 03:51 |
|
I've been using python-mode in Vim. I am working on building a library in a subfolder. Each time I change files within the library, I have to restart vim for it to reload the library. Is there any way to force reloading of the library when I execute in Vim?
|
# ? Nov 29, 2018 04:43 |
|
To improve my python skills (and to be reminded how I still know even a tiniest fraction about it) I figured to give https://adventofcode.com/2018 a shot. While I managed to solve the issue at hand, I figured I'd post it here to get some feedback on it, as well as wondering how to do a particular thing different. The assignment was loop through a list of numbers with an operator in front of it that indicates if you should add/subtract the number from the previous number. The assignment was to calculate a "frequency", which is why my variables are called "freq" and the likes. The script should stop when it ran into the first duplicate frequency. You had to run the program multiple times since the first (few?) iteration(s) did not result in duplicate numbers. I'm aware that using global is bad practise. I can't figure out why the program won't work without it though. When referencing freq_list or duplicate_freq from inside the run_freq_calc() function, it doesn't run into issues, but if I do that with curr_freq it throws an UnboundLocalError: local variable 'curr_freq' referenced before assignment error. I've got no idea why that's happening. Besides this question, any other feedback on my code would be more than welcome. Python code:
|
# ? Dec 3, 2018 12:28 |
|
Python's variables are basically key/value pairs in a local dictionary, so when you assign butt = 69 it's adding an entry to that. If you try to reference a variable before you assign it, it's like looking up a key that doesn't exist (+= is basically 3 operations - read, increment, write) The global keyword basically makes that global value accessible so you can look it up in the global dictionary, or however it works under the hood. You can access it, anyway (hope the dictionary stuff is still true...)
|
# ? Dec 3, 2018 13:07 |
|
baka kaba posted:Python's variables are basically key/value pairs in a local dictionary, so when you assign butt = 69 it's adding an entry to that. If you try to reference a variable before you assign it, it's like looking up a key that doesn't exist (+= is basically 3 operations - read, increment, write) Thanks for explaining. I can’t believe I’ve never ran into this issue before though. On Stack Overflow it’s mentioned multiple times that this is not a pythonic way to do things. Any ideas on how I could avoid this?
|
# ? Dec 3, 2018 18:34 |
|
LochNessMonster posted:Thanks for explaining. I can’t believe I’ve never ran into this issue before though. Pass it in as, say, starting_freq. I'd say pass in the list, and the duplicate flag, too, tbh.
|
# ? Dec 3, 2018 18:37 |
|
Pass yr stuff in to the function! So you're referring to a parameter that's in scope, and then you can return a result to the calling function instead of updating a global flag And sorry, I wasn't completely right about the local thing. Basically if you write to a variable somewhere in a function, Python assumes you're creating a local variable with that name and assigning to it. So when you try to read that same variable earlier in the function, before you've assigned to it, Python looks in the local dictionary for something that hasn't been added yet Adding the global keyword basically tells it to go looking in higher scopes instead. But if all you do in the function is read a global value, it'll go looking automatically, so you don't need to specify global, which is probably why you haven't run into it before. Like I said, += is a read-increment-write operation, so it creates a local variable (because of the write) but the first thing you do with it is attempt a read before it's been set to anything, so you get the error
|
# ? Dec 3, 2018 18:50 |
|
Instead of relying on the global namespace, pass your data between your functions. In your case, you are not actually using the input/output of the function in any way. Best practice would be to not refer to any variables outside the function, even the ones where it works without global. Instead, pass them in. And then, if you are basically passing the program's entire state in and out of the function, then you could probably improve how you break down your program into functions. Because I'm a procastinator I signed up for AOC; here's my answer: Python code:
SurgicalOntologist fucked around with this message at 19:00 on Dec 3, 2018 |
# ? Dec 3, 2018 18:57 |
My 5 minute take on the exercise:Python code:
cinci zoo sniper fucked around with this message at 19:06 on Dec 3, 2018 |
|
# ? Dec 3, 2018 19:03 |
|
Thanks for all the great examples. Before posting I did try passing curr_freq to the function but my program then stopped at the 1st value of the 2nd pass of the input file. Made me think that the value for curr_freq was reset to 0 and then the first value of the 2nd pass would always be the first duplicate. I'm not really sure why it does that. I expected the variable to be updated each time the function is executed, but apparently each iteration of the function takes the (global) curr_freq = 0 as a start again. So just passing it to the function is not enough. While typing this I figured out how to solve it. It's just as dirty as the rest of the code but it does the job. Python code:
|
# ? Dec 3, 2018 19:26 |
|
That's good, next step would be to make duplicate_freq not a global variable either (i.e. return it from the function). Also instead of while duplicate_freq == False it would be idiomatic to do while not duplicate_freq.
|
# ? Dec 3, 2018 19:55 |
|
Mine was certainly not fast to run in PyCharm, because of adding each item to a list which ended up with 142,990 items, but it worked.Python code:
Sad Panda fucked around with this message at 22:17 on Dec 3, 2018 |
# ? Dec 3, 2018 22:12 |
|
LochNessMonster posted:Thanks for all the great examples. You probably forgot to return the new value of curr_freq when you tried that, or you forgot to use the local variable name instead of the global one
|
# ? Dec 3, 2018 22:16 |
|
This is more of a software-design question and I'm having trouble remembering the "pythonic" or "preferred" way of doing it so its more testable: I'm using a Python JIRA library to interact with the JIRA Service Desk (help desk sort of thing). There's a requirement to support different "support ticket" backends, so I figured I would create TicketManager class that wraps around the JIRA Library to give a standard interface for any of the functionality I plan on using. I also have to work with individual support tickets, so I created a Ticket library that takes in a JIRA "issue" object and I can call methods on that. So I have: code:
|
# ? Dec 4, 2018 07:26 |
Fluue posted:This is more of a software-design question and I'm having trouble remembering the "pythonic" or "preferred" way of doing it so its more testable: Looks fine, in my opinion.
|
|
# ? Dec 4, 2018 08:34 |
|
What I want to do: Split a dataframe column of name strings into first and last names using nameparser. Have the first and last names in their own columns. Problem: I get an object with the original name which contains all of the name parts in a "name" object rather than a series that is appended as new columns. Any suggestions on how to properly solve this problem? code:
code:
EDIT: This worked. code:
CarForumPoster fucked around with this message at 13:24 on Dec 4, 2018 |
# ? Dec 4, 2018 12:49 |
|
I have a bunch of functions in a custom module in Django that performs a bunch of helm stuff for kubernetes via subprocess. I decided to split those functions out to helm.py and now my custom module has "from . import helm" and a bunch of statements that look like helm.init(), helm.repo_update() etc. Then I went crazy and pulled out most everything from my original custom module and put them in to their own 4 modules. Line count dropped from 180 down to about 55. From my perspective I greatly increased readability and made it easier to maintain, especially as additional features get added. Is there any problem with this? Nothing computationally data heavy, just process stuff for CI/CD.
|
# ? Dec 5, 2018 00:49 |
|
I suck at encoding and I am having a stupid problem. I am using requests to get XML from a web service. It returns unicode, which I verified by doing (2.7.13):code:
code:
code:
|
# ? Dec 5, 2018 20:15 |
|
Encoding is terrible and you shouldn't be using 2.7 unless someone is forcing you to. That being said, take a look at the normalize function in unicodedata
|
# ? Dec 5, 2018 20:48 |
|
I'm only using 2.7 because I have a legacy codebase that I'm too lazy to port over to 3. It's doing something pretty trivial and I'm sure I'll move it over sometime in the next few months but it's super low on the priority list. I'll check that link out. Thanks.
|
# ? Dec 5, 2018 21:09 |
|
If I initialize a variable within a class method, does it have to use the self prefix? code:
code:
|
# ? Dec 5, 2018 21:17 |
|
Gothmog1065 posted:If I initialize a variable within a class method, does it have to use the self prefix? Not using self means that you've defined a class attribute. This is valid, all instances of the class are accessing a shared version of the variable and that may be the behavior that you want. foo.num and bar.num will always be the same value in your code Using self creates an instance attribute, meaning all instances of the classes are accessing their own version of the variable. Declaring "self.num = 0" in your constructor creates an instance attribute, and then foo.num and bar.num can be different values
|
# ? Dec 5, 2018 21:47 |
|
I'm doing a bunch of computations and saving them to a database. The following function is supposed to be committing to the database every 100 results (based on the variable commit_interval), and stopping after 10,000 (the value of total). But I'm not getting 10,000 results on each backtest_set, instead I'm getting 9,900. Can anyone spot the error? Am I making a basic off-by-one -ish mistake or do I have some weird race condition? I can't figure it out. Here's the code.Python code:
The actual work is here is done inside the generator function backtest_set.run(). And if you haven't seen it before, tqmd is just a progress bar library (a pretty great one), as I'm using it just wraps an iterable. The only other things there are my models and sqlalchemy session db.
|
# ? Dec 6, 2018 03:42 |
|
|
# ? May 14, 2024 16:45 |
SurgicalOntologist posted:I'm doing a bunch of computations and saving them to a database. The following function is supposed to be committing to the database every 100 results (based on the variable commit_interval), and stopping after 10,000 (the value of total). But I'm not getting 10,000 results on each backtest_set, instead I'm getting 9,900. Can anyone spot the error? Am I making a basic off-by-one -ish mistake or do I have some weird race condition? I can't figure it out. Here's the code. If your dataset has only 10000 records for test then this will be off by one error, maximum i is 9999 and can not be equal 10000, and the last modulo operation will resolve to not True.
|
|
# ? Dec 6, 2018 05:25 |