|
Tigren posted:Your string substitution is out of place. I'll read up on that, thanks. I have done several tutorials and didn't come across string substitution yet, so I'v been googling that part. I'm indeed using python3 so that's probably my first issue. I noticed you mentioned my for loop overwriting the variable with each iteration but changed your reply so it's gone. That was a relevant remark as well though, I'm kinda ashamed I didn't notice that myself.
|
# ? Nov 2, 2016 21:24 |
|
|
# ? May 9, 2024 08:57 |
LochNessMonster posted:I noticed you mentioned my for loop overwriting the variable with each iteration but changed your reply so it's gone. That was a relevant remark as well though, I'm kinda ashamed I didn't notice that myself. Half the code I post on this site has some stupid mistake like that, so don't sweat it. It happens.
|
|
# ? Nov 2, 2016 21:32 |
|
LochNessMonster posted:I'll read up on that, thanks. I have done several tutorials and didn't come across string substitution yet, so I'v been googling that part. I'm indeed using python3 so that's probably my first issue. Sorry about that. When I first read your post, I thought this was for displaying all vehicles for all dealers. I figured you were iterating through a list of dealerNames, but only getting one dealer's worth of dealerVehicles. If that's the case, then yes, you'll want to append dealerVehicles to a list or dictionary at the end of the loop, like this: Python code:
HTML code:
|
# ? Nov 2, 2016 22:02 |
|
str.format is also in py2, what do you guys mean?
|
# ? Nov 2, 2016 22:23 |
|
Just a heads up for good programming practices, don't do string interpolation on sql queries:Python code:
Python code:
Python code:
|
# ? Nov 2, 2016 22:23 |
|
Cingulate posted:str.format is also in py2, what do you guys mean? >= py2.6 to be exact I guess
|
# ? Nov 2, 2016 23:02 |
|
I hate it in py2.6 because you have to provide indexes. But I hate py2 generally in 2016
|
# ? Nov 2, 2016 23:11 |
|
Hed posted:I hate it in py2.6 because you have to provide indexes. But I hate py2 generally in 2016
|
# ? Nov 2, 2016 23:27 |
Is python 2.6 still the default python for CentOS? The only time I ever see it nowadays is on old CentOS machines.
|
|
# ? Nov 3, 2016 01:07 |
|
Symbolic Butt posted:Just a heads up for good programming practices, don't do string interpolation on sql queries: my query_db function is based on the following functions, so I am using cursor.execute, just calling it with another function. For some reason I just can't get it to work. Python code:
code:
edit: maybe I should clearify what I'm trying to achieve a bit better. I currently have 40ish dealers. For each dealer I'd like to have a url ../dealers/<dealerName> which displays all vehicles for this dealer. I still have a feeling I'm doing this completely wrong, but can't figure out what. edit2: I managed to get it working with (dealer) instead of [dealer] Python code:
And it displays all vehicles/dealers on each page, but that's something I need to fix in the jinja template. LochNessMonster fucked around with this message at 10:51 on Nov 3, 2016 |
# ? Nov 3, 2016 08:26 |
|
That error message is saying the parameter you're feeding in (dealer) is the wrong type. It's probably expecting a string or another primitive like an int, and dealer is probably some kind of record object instead. Try passing in str(dealer) e- me read good baka kaba fucked around with this message at 14:48 on Nov 3, 2016 |
# ? Nov 3, 2016 14:38 |
|
Minor nitpick on your query_db function. When you want to return only one result, you shouldn't pick the first result from cur.fecthall, you should use cur.fetchone instead, like so: Python code:
|
# ? Nov 3, 2016 14:54 |
|
For anyone interested, I'm posting part of my ipython config, which includes auto-imports of common math(s) functions and constants. Ie, like Julia:Python code:
|
# ? Nov 6, 2016 19:39 |
|
Which one should I do? (Or: when should I do which)code:
|
# ? Nov 9, 2016 22:35 |
|
Cingulate posted:Which one should I do? (Or: when should I do which) I think #1 is better for both readability and computational efficiency, but you should use a set instead of a tuple, aka set numbers to set((100,200,300))
|
# ? Nov 9, 2016 22:42 |
|
Cingulate posted:Which one should I do? (Or: when should I do which) Do #2 when the collection is only small, is used in only one place, and is not configurable. code:
|
# ? Nov 9, 2016 22:51 |
Cingulate, the answer is 'it depends'. If there's some name that accurately describes your container's contents, use that. On the other hand, sometimes your container explains itself. EG: Python code:
If your possible elements are very small, it's OK to test membership in a list or tuple. But it's good to get in the habit of testing membership in sets, because this will save you headaches down the line. Testing membership in a list or tuple is O(n), where testing membership in a set via hash function is O(1). Python code:
Eela6 fucked around with this message at 03:25 on Nov 10, 2016 |
|
# ? Nov 9, 2016 23:08 |
|
Thanks guys!Eela6 posted:Testing membership in a list or tuple is O(n), where testing membership in a set via hash function is O(1).
|
# ? Nov 10, 2016 13:04 |
|
They're both O(n), though the CPU time per element is higher for sets than lists or tuples since each element has to be hashed instead of simply storing a reference in the collection. If you're only doing a single membership test (i.e. not in a loop), you may as well just check for item in list or item in tuple -- you don't really recoup the cost of building a set until at least the second membership test.
|
# ? Nov 10, 2016 13:16 |
|
Intuitively, I'd use the tuple instead of the list then because for a one-shot, it seems more appropriate. (Or the set if it's longer or reused or whatever)
|
# ? Nov 10, 2016 13:46 |
|
Huge caveat, though: what I said only applies if you're storing the collection in a variable and then performing membership tests after that (or if the collection can change at runtime, of course). When using a set literal, with values known at compile-time, Python's peephole optimizer replaces the set with a frozenset which is precomputed when the code is compiled:code:
|
# ? Nov 10, 2016 19:15 |
|
Cingulate posted:Intuitively, I'd use the tuple instead of the list then because for a one-shot, it seems more appropriate. (Or the set if it's longer or reused or whatever) You'd want to use the set if you're checking for membership more than once, because otherwise membership checking is expensive (O(n)). And you don't want to define the set inside of the for loop because defining a set is expensive (O(n)).
|
# ? Nov 10, 2016 21:21 |
|
The chances are super high that you should use whatever you want because the performance differences are going to be minuscule for your application.
|
# ? Nov 10, 2016 21:32 |
Thermopyle posted:The chances are super high that you should use whatever you want because the performance differences are going to be minuscule for your application. Yes. I tend to emphasize 'always test membership in sets! ' because most of the python programmers I know are academics who are not professional programmers. Teaching them this way avoids the worst - case scenarios.
|
|
# ? Nov 10, 2016 21:44 |
|
What are some good ways to learn how to structure Python programs? I've been looking at some of the projects listed here https://www.reddit.com/r/Python/comments/1ls7vq/best_written_projects_on_python_github/ but not seeing the decision process that goes behind the design. Part of the issue is that my scripts are very linear so I don't really need to make much of OO design. But I worry I'm missing other things due to not having a CS background. Suggestions? I've been writing scripts for literally years but when I look at a big project like Tornado or Flask it seems very different than something I would write. I've read all the books but they're all about syntax and not really about the big picture/design.
mr_package fucked around with this message at 00:33 on Nov 11, 2016 |
# ? Nov 10, 2016 23:54 |
|
-
|
# ? Nov 11, 2016 00:07 |
|
mr_package posted:What are some good ways to learn how to structure Python programs? I've been looking at some of the projects listed here https://www.reddit.com/r/Python/comments/1ls7vq/best_written_projects_on_python_github/ but not seeing the decision process that goes behind the design. Part of the issue is that my scripts are very linear so I don't really need to make much of OO design. But I worry I'm missing other things due to not having a CS background. Suggestions? I've been writing scripts for literally years but when I look at a big project like Tornado or Flask it seems very different than something I would write. I've read all the books but they're all about syntax and not really about the big picture/design. Unfortunately, I don't know a good answer for this other than writing a lot of code.
|
# ? Nov 11, 2016 00:59 |
|
mr_package posted:What are some good ways to learn how to structure Python programs? I've been looking at some of the projects listed here https://www.reddit.com/r/Python/comments/1ls7vq/best_written_projects_on_python_github/ but not seeing the decision process that goes behind the design. Part of the issue is that my scripts are very linear so I don't really need to make much of OO design. But I worry I'm missing other things due to not having a CS background. Suggestions? I've been writing scripts for literally years but when I look at a big project like Tornado or Flask it seems very different than something I would write. I've read all the books but they're all about syntax and not really about the big picture/design. I recommend reading through at least the Python parts of this book, though. Much of the book is in Python, and about Python projects, so just pick some chapters that seem interesting and dive in. EDIT: Also, look at the code of the projects you use a lot. I use Requests all the drat time, and I've browsed the code when i have questions about the internals and learned a bunch. Since you probably understand the API and how to use it, you can get a good grasp of the internals pretty quickly. Also, the book has a chapter by Guido on asyncio, which loving rules Ghost of Reagan Past fucked around with this message at 18:14 on Nov 12, 2016 |
# ? Nov 12, 2016 18:05 |
|
Thanks, I don't think these books ever came up in my research on this I will give it a read. I was in fact just thinking it made little sense to try to study Flask when I'm not writing anything web-app. Too bad pyodbc is C. But I did work with Pillow/PIL a lot in the past so maybe that's a place to start. I wrote some functions that might even be good to contribute back to that project actually.
|
# ? Nov 13, 2016 04:44 |
|
What is a good python IDE that integrates will with Docker? I write 99% of my code in R, and I have RStudio Server loaded into a docker container (with all appropriate libraries installed via the Docker file). I then load my R scripts into the container by sharing volumes/folders and work on them in the IDE interactively via the browser (ie RStudio Server). I can then run my finished code using the R command line executable from within the Docker container. Is there anything like that for Python? Basically I want to be able to write code in an interactive way, and then be able to run it via command line without changing anything. The command line part needs to be able to be completely encapsulated withon Docker for portability reasons.
|
# ? Nov 13, 2016 08:16 |
|
Womens Jeans posted:What is a good python IDE that integrates will with Docker? PyCharm. (I don't know if you can exactly mirror your R experience, but I think it does have Docker support, and I do know it has support for working with remote interpreters) Thermopyle fucked around with this message at 16:43 on Nov 13, 2016 |
# ? Nov 13, 2016 16:40 |
|
Womens Jeans posted:What is a good python IDE that integrates will with Docker? The new JupyterLab under development has lots of plugins and various different modes in addition to the "Classic Jupyter Notebook" interface, some of them are more like IDEs, ala RStudio
|
# ? Nov 15, 2016 05:06 |
|
Got a few months before I start a new job and I want to use it to brush up on my Python skills, especially data analysis. Can anyone recommend any good books or online courses ideally focusing on the SciPy/NumPy stack? I've done a few online courses so I'm familiar with all the components but I'd like something a bit more in-depth and advanced than what's available on EdX. Thanks!
|
# ? Nov 15, 2016 16:52 |
|
Zekky posted:Got a few months before I start a new job and I want to use it to brush up on my Python skills, especially data analysis. Can anyone recommend any good books or online courses ideally focusing on the SciPy/NumPy stack? I've done a few online courses so I'm familiar with all the components but I'd like something a bit more in-depth and advanced than what's available on EdX. Thanks!
|
# ? Nov 15, 2016 17:20 |
|
Cingulate posted:Participate in a Kaggle competition? Looks cool thanks for the tip. Surprised I've never seen this before actually.
|
# ? Nov 16, 2016 00:30 |
|
Zekky posted:Got a few months before I start a new job and I want to use it to brush up on my Python skills, especially data analysis. Can anyone recommend any good books or online courses ideally focusing on the SciPy/NumPy stack? I've done a few online courses so I'm familiar with all the components but I'd like something a bit more in-depth and advanced than what's available on EdX. Thanks! Do your own project and put it on your github for next time you're looking for a job. Write a library, do some analysis of something.
|
# ? Nov 16, 2016 01:25 |
|
I'm using pandas to update a column in a dataframe. My rules are if there is a value in the New column, that becomes the Current value. If there is a NaN in the New column, the value in the Old column becomes the Current value code:
code:
Please help, I'm bad and new at this.
|
# ? Nov 18, 2016 18:00 |
You want to use numpy / MATLAB style logical indexing. numpy has a number of formal logic operators that are what you want, called logical_and, logical_not, logical_xor, etc... It's easiest to understand given an example. You might already know this, but it's always nice to have a refresher. IN: Python code:
Python code:
IN: Python code:
code:
Eela6 fucked around with this message at 23:11 on Nov 18, 2016 |
|
# ? Nov 18, 2016 18:55 |
|
I'll have to look closer when not on a phone but can definitely use & and | for row indexing in pandas. I'm pretty sure your .loc[] commands are slightly wrong from a quick glance. Here's what you want code:
vikingstrike fucked around with this message at 20:57 on Nov 18, 2016 |
# ? Nov 18, 2016 20:07 |
|
|
# ? May 9, 2024 08:57 |
|
Not Pandas style, but what aboutcode:
|
# ? Nov 18, 2016 21:56 |