|
Thermopyle posted:In other news I've been spending some time recently converting a bunch of bash scripts to python because gently caress bash. This is neat. I've used sh for this in the past, but plumbum looks a bit more featureful. Does it handle piping properly (i.e. hooking stdin/stdout of the processes together at the OS level) or does it shuffle everything through python? I've used a few shell replacement libraries that do the later and it can be a real show stopper if you need to move a large amount of data around. A bit of fuckery is worth it though, just to avoid bash's insane string quoting rules. Nippashish fucked around with this message at 12:48 on Feb 5, 2017 |
# ? Feb 5, 2017 12:43 |
|
|
# ? May 8, 2024 05:31 |
|
Any suggestions for naming variables in Python for loops? I tend to just go with each or index but it gets quite confusing if I'm nesting loops. I also sometimes use, if my list is named something like "pairs" I'll do for each pair in pairs but that also seems a bit chaotic.
|
# ? Feb 5, 2017 22:21 |
|
huhu posted:Any suggestions for naming variables in Python for loops? I tend to just go with each or index but it gets quite confusing if I'm nesting loops. I also sometimes use, if my list is named something like "pairs" I'll do for each pair in pairs but that also seems a bit chaotic. code:
|
# ? Feb 5, 2017 22:25 |
Python code:
Eela6 fucked around with this message at 00:21 on Feb 6, 2017 |
|
# ? Feb 6, 2017 00:07 |
|
QuarkJets posted:
I'm not sure you understand what you highlighted in my quote means? I mean...using your own style in a code base is bad and worse than using a less popular convention for an unused variable. I'm not sure what's controversial about that. HardDiskD posted:I mean, gently caress bash and that's a really sexy API, but I feel like this is just hiding the bash under a Python rug and calling it a day. That's kind of what we do as programmers, no? Nippashish posted:This is neat. I've used sh for this in the past, but plumbum looks a bit more featureful. Does it handle piping properly (i.e. hooking stdin/stdout of the processes together at the OS level) or does it shuffle everything through python? I've used a few shell replacement libraries that do the later and it can be a real show stopper if you need to move a large amount of data around. A quick perusal of the source makes it look like it uses OS piping via popen, but I'm not 100% confident in that. https://github.com/tomerfiliba/plumbum/blob/1441c5ae7dedc2f40aaf37207ff2585557c5746b/plumbum/commands/base.py#L266 Tigren posted:That does seem fun, but why not learn the Standard Library os module and rely on subprocess when needed? They're already included for you. I kind of feel like the answer to this is similar to the answer I gave HardDiskD. The only reason to use any library is if it makes your job easier...after all you can implement anything you want yourself. You could use C instead of Python. You could use assembly instead of C. It just might be easier to implement the functionality you need by using subprocess, or it might not. I've used subprocess extensively, but it's certainly not as concise as this particular library. This library seems to make it easier to express what you intend.
|
# ? Feb 6, 2017 00:37 |
HardDiskD posted:I mean, gently caress bash and that's a really sexy API, but I feel like this is just hiding the bash under a Python rug and calling it a day. That's good! It's called the adapter pattern, and it's often a mark of pythonic code. Raymond Hettinger's talk "Beyond PEP8" goes into this kind of thing in detail (his example hides a Java api under a python rug, but the thrust is the same)
|
|
# ? Feb 6, 2017 00:57 |
|
Thermopyle posted:I'm not sure you understand what you highlighted in my quote means? In the text that I highlighted you're subtly implying that using _ for unused variables is objectively better than other conventions. It's the "vim vs emacs" of variable naming; both options are fine and if you're starting a new codebase then it's fine to use whatever you want
|
# ? Feb 6, 2017 04:58 |
|
What IDEs do people like for doing data stuff in Python? I've been just using Spyder or Jupyter notebooks pretty much because they were the default options w/ Anaconda. Has anyone found that a different IDE has some particular benefits?
|
# ? Feb 6, 2017 09:07 |
|
Fusion Restaurant posted:What IDEs do people like for doing data stuff in Python? I've been just using Spyder or Jupyter notebooks pretty much because they were the default options w/ Anaconda. Data scientist checking in PyCharm is not really made with data analysis in mind but it is still a really great IDE. It's what I use when it's available and when I'm not being lazy/opening Vim for a quick thing. Spyder is solid but debugging in it is a real chore compared to PyCharm. I think it also doesn't have native version control and that its code refactoring tools are per-file rather than per-project, but I could be wrong; I haven't used it in a long time. I think it's only as popular as it is because it comes with Anaconda and PyCharm doesn't, so it's sort of the path of least resistance. Jupyter notebooks are cool but I don't really use them, so I can't comment on their effectiveness as an IDE. Creating a new notebook felt clunky and weird when I was playing around with it. However, I do know that PyCharm lets you open Jupyter notebooks, so it seems like you should be able to have the best of both worlds if a notebook suits your needs
|
# ? Feb 6, 2017 09:47 |
|
I've completed the code academy course and am working on the MIT open courseware course recommended in the OP. It's been a lot easier than I thought to learn to code but, one thing I've been wanting to know is how do I go about drawing geometric shapes? None of the lessons I've done so far cover any kind of drawing.
|
# ? Feb 7, 2017 04:24 |
|
Azuth0667 posted:I've completed the code academy course and am working on the MIT open courseware course recommended in the OP. It's been a lot easier than I thought to learn to code but, one thing I've been wanting to know is how do I go about drawing geometric shapes? None of the lessons I've done so far cover any kind of drawing. May be too basic, but how about the turtle module? http://greenteapress.com/thinkpython2/html/thinkpython2005.html
|
# ? Feb 7, 2017 04:44 |
|
Azuth0667 posted:I've completed the code academy course and am working on the MIT open courseware course recommended in the OP. It's been a lot easier than I thought to learn to code but, one thing I've been wanting to know is how do I go about drawing geometric shapes? None of the lessons I've done so far cover any kind of drawing. If you want to use python to draw geometry I'd say look at pillow https://python-pillow.org/ - then I'd say that pillow kind of sucks and that Python isn't a super great language for doing this kind of thing (visual work). What exactly is it that you want to use the shapes for?
|
# ? Feb 7, 2017 05:16 |
|
The March Hare posted:If you want to use python to draw geometry I'd say look at pillow https://python-pillow.org/ - then I'd say that pillow kind of sucks and that Python isn't a super great language for doing this kind of thing (visual work). What exactly is it that you want to use the shapes for? I want to be able to make a grid out of them and assign each one a different random number.
|
# ? Feb 7, 2017 05:24 |
|
Azuth0667 posted:I want to be able to make a grid out of them and assign each one a different random number. OK, yeah, I would use Pillow - should be fine.
|
# ? Feb 7, 2017 05:49 |
|
Azuth0667 posted:I want to be able to make a grid out of them and assign each one a different random number. But what are you going to do with that? If you have a bigger end goal in mind (like making an interactive sudoku grid or something) you might want to get learning a GUI library that will handle all the inputs and stuff
|
# ? Feb 7, 2017 08:12 |
|
baka kaba posted:But what are you going to do with that? I'm trying to make an example of viral infection of cells for an intro class. Basically I want to be able to let the students choose a couple cells then have the infection spread based on what kind of virus it was. It will have to check if the cell is already infected, is it in division - what phase of division, is it senescent, does it have a lot of resources, does it have a lot of waste products, what kind of cell is it? If the conditions are true for that virus then it spreads to that cell. Most of those conditions seem like I could model them as booleans or integers. The first step I have laid out is to take a square grid then fill it with closed shapes that are touching each other. I want to assign different random values representing the conditions I listed above and to visually indicate this by filling the respective shape with a color. Next I'm going to get a student volunteer to come up and pick the cell to be infected and do that until I've run out of viruses to use. Then watch the spread of the virus through the cells.
|
# ? Feb 7, 2017 16:35 |
|
Azuth0667 posted:I'm trying to make an example of viral infection of cells for an intro class. Basically I want to be able to let the students choose a couple cells then have the infection spread based on what kind of virus it was. It will have to check if the cell is already infected, is it in division - what phase of division, is it senescent, does it have a lot of resources, does it have a lot of waste products, what kind of cell is it? If the conditions are true for that virus then it spreads to that cell. Most of those conditions seem like I could model them as booleans or integers. This sounds like something you might be able to accomplish using Agent Based Simulation. I have never used Mesa (https://pypi.python.org/pypi/Mesa/), but it should allow you to do what you want. You will have to write the rulesets for how viruses spread etc, but not have to worry about writing the graphics side of things.
|
# ? Feb 7, 2017 17:00 |
|
http://py.processing.org/tutorials/drawing/ in combination with some Processing videos from The Coding Train youtube channel guy could get you started with drawing stuff pretty easily
|
# ? Feb 7, 2017 17:43 |
|
I'm trying to make the transition to python 3.6, and am wondering if there are any helpful resources online that summarize the big changes in python 3? I found the What's New section of the official documentation, but am looking for more of a Cliff Notes version until I have time to finish reading through the docs.
|
# ? Feb 7, 2017 21:49 |
|
A few highlights: -Built-in functions tend to return iterators rather than lists. Ie range(), .items(), map() etc. -Division doesn't auto-round. -string encoding is handled differently -print is a function -Python 3 supports a number of new features. I'd just dive in, and fix things as they break. You can try the new features once you're comfortable with the changes. Dominoes fucked around with this message at 22:02 on Feb 7, 2017 |
# ? Feb 7, 2017 21:59 |
vikingstrike posted:I'm trying to make the transition to python 3.6, and am wondering if there are any helpful resources online that summarize the big changes in python 3? I found the What's New section of the official documentation, but am looking for more of a Cliff Notes version until I have time to finish reading through the docs. IN: Python code:
Python code:
Here's a somewhat contrived example to show why iterators and generators are such a big deal: IN: Python code:
code:
Eela6 fucked around with this message at 23:43 on Feb 7, 2017 |
|
# ? Feb 7, 2017 23:20 |
|
I'm documenting some tutorials/examples with Sphinx and for each tutorial (it's a python module/script) I'm writing the documentation at the module level docstring and then using automodule in my docs/source directory to get it generated. I want to include the actual code into the HTML page that gets generated. How do I do that? I tried with 'literalinclude' but this, well, literally includes also its docstring which I don't want. I guess I could just specify which lines to include but it would be better if it would automatically just include everything below the module level docstring. Secondly is there a variable I can tell the docstring to include itself (with its path automatically expanded)? Right now I have to do "literalinclude: ../../tutorials/.." and so on. I'd like to just do something like "literalinclude: $SELF".
|
# ? Feb 8, 2017 14:45 |
I think this is more of a Python question than a Django question... I'm using django-after-response to invoke a long method after a request completes. I want to log that long running method in a separate file (as well as to the normal application log) so I do the following: code:
|
|
# ? Feb 8, 2017 20:34 |
|
What's tkinter like for working with accessibility things like a screen reader? All the articles I can find suggest the situation is pretty dire, but they're also something like three or four years old -- have things gotten any better, or am I better off switching to a different toolkit?
|
# ? Feb 9, 2017 13:25 |
|
fletcher posted:I think this is more of a Python question than a Django question... Just spitballing here, but try to give the NamedTemporaryFile an unique prefix and/or suffix? Also, you might want to give it delete=False.
|
# ? Feb 9, 2017 13:36 |
|
Hey dudes. Looking to see if there are pre-built solutions that would help for a project I'm going to undertake for work. I'm trying to build a scheduler app for a flying club. In early planning stages. Currently, we have a white board, and magnetic name tags we shift around. The schedule changes frequently, and there are different qualifications, training requirements etc each person maintains that place constraints on the scheduling. Subject to chaos, people getting sick, last-minute changes etc. Thought 1: Scheduling? Aren't there a bunch of already made solutions, since it's such a common task? Thought 2: This seems like a unique use case, with many non-standard variables; roll your own rather than fit a square peg in a round hole. Thoughts?
|
# ? Feb 9, 2017 22:52 |
|
Dominoes posted:.... Eela6 posted:... Thanks!
|
# ? Feb 9, 2017 23:15 |
|
I'm building a webcam that pushes images to the internet after capture. I found a script to upload the images to Dropbox and it works great. However, I've found an issue that if the internet goes down mid upload, no error is returned and the upload just gets stuck at whatever percent its at. This wouldn't really be an issue however my hackspace's internet is utter garbage and I suspect the internet will go down pretty often. Is there some nifty way to detect a stuck upload and break?
|
# ? Feb 10, 2017 01:27 |
|
huhu posted:I'm building a webcam that pushes images to the internet after capture. I found a script to upload the images to Dropbox and it works great. However, I've found an issue that if the internet goes down mid upload, no error is returned and the upload just gets stuck at whatever percent its at. This wouldn't really be an issue however my hackspace's internet is utter garbage and I suspect the internet will go down pretty often. Is there some nifty way to detect a stuck upload and break? If your script uses the Dropbox v2 API, it looks like it raises a requests.exceptions.ConnectionError when it times out. code:
Tigren fucked around with this message at 03:34 on Feb 10, 2017 |
# ? Feb 10, 2017 02:14 |
|
Tigren posted:If your script uses the Dropbox v2 API, it looks like it raises a requests.exceptions.ConnectionError when it times out.
|
# ? Feb 10, 2017 05:31 |
Hey so what's the state of the art way of doing packaging? I want something where I can run some command(s) on the command line and it'll download all the right dependencies for my script, download the right version of python, and run the script. But it seems like there are a million different tools that each do a part of this and it's not really clear to me how they intersect.
|
|
# ? Feb 10, 2017 07:22 |
|
huhu posted:I think that error message is hidden away in the script I found on Github. Can you link to the script you're using? The Dropbox python API is very straight forward if you just want to write your own. Python code:
quote:Upload succeeded: FileMetadata(name='file', id='id:UmsjUZ9eogAAAAAAAAAACg', client_modified=datetime.datetime(2017, 2, 10, 7, 1, 10), server_modified=datetime.datetime(2017, 2, 10, 7, 1, 10), rev='8540e8f17', size=6, path_lower='/path/to/file', path_display='/path/to/file', parent_shared_folder_id=None, media_info=None, sharing_info=None, property_groups=None, has_explicit_shared_members=None)
|
# ? Feb 10, 2017 08:08 |
|
VikingofRock posted:Hey so what's the state of the art way of doing packaging? I want something where I can run some command(s) on the command line and it'll download all the right dependencies for my script, download the right version of python, and run the script. But it seems like there are a million different tools that each do a part of this and it's not really clear to me how they intersect. I'm not an expert either but I think these two links should help: https://packaging.python.org/distributing/ https://github.com/pypa/sampleproject If you clone the sampleproject you should be able to customize it to your own package and then just run a pip install . from your project directory. You should be able to configure it to download Python dependencies as well. I think if you want to manage non-Python dependencies then you'll have to use Conda/Anaconda, like "download the right version of python." Though I gotta wonder why do you think you need to manage the actual Python installation yourself? That just seems unnecessarily complicated and unless you specifically need to do for whatever reason that then wouldn't it be better off just testing your script against different Python versions? The sampleproject I linked has some scripts/tools that do just that for you, automatically.
|
# ? Feb 10, 2017 09:55 |
|
Dominoes posted:Thoughts? Sounds like you want a rules engine.
|
# ? Feb 10, 2017 14:43 |
|
If I need to edit some audio files (mp3 & wav) I should just use FFmpeg right? Is there some super secret audio editing package in Python that I don't know about? I'm just going to be selectively muting sections of audio based on timestamps, so nothing super fancy.
|
# ? Feb 10, 2017 14:58 |
|
Tigren posted:Can you link to the script you're using? The Dropbox python API is very straight forward if you just want to write your own. Oh that's much nicer than what I'm using, thanks.
|
# ? Feb 10, 2017 15:51 |
|
The March Hare posted:If I need to edit some audio files (mp3 & wav) I should just use FFmpeg right? Is there some super secret audio editing package in Python that I don't know about? I'm just going to be selectively muting sections of audio based on timestamps, so nothing super fancy.
|
# ? Feb 10, 2017 16:16 |
|
Cingulate posted:You can do that in Scipy, with wavread. It's just one or two lists (arrays) of numbers; sample rate plus time stamp gives you the indices, then you set these to zero and write back the file. Can it deal w/ MP3s though?
|
# ? Feb 10, 2017 16:22 |
|
Anyone used uvloop as a replacment for the async event loop? I've got an async-using application that is going to be approaching some limits in requests per second and I'm researching some of my alternatives and uvloop looks promising...
|
# ? Feb 10, 2017 20:30 |
|
|
# ? May 8, 2024 05:31 |
|
I have a data set that has a lot of features. Each row is an event but each event is part of a larger event (it's power outage data, I have bulk outage events, broken down into restoration steps, as well as geographical categories, device categories, etc.) I want to be able to "collapse" different categories so that, say I just have a total time elapsed for one outage event by summing over the time taken in each restoration step, but maintain dataframe structure so that if I wanted to break it down further into GIS or month, or whatever sub categories, it would be easy to do later on. As such, I'm trying to develop a function that will take a df, a column name to categorize rows into, and a column name that is summed in each category. I'd like to keep it as standalone as I can so I can collapse these indices in different ways depending on what features I want to study. right now I have:code:
semi-related: is there a data science thread? I suppose it could be either in here or in SAL. edit: there might be a much better way to do this, too. I'm new to doing this stuff with python so I'm still learning a lot of the methods that I can use stock. GrAviTy84 fucked around with this message at 21:36 on Feb 10, 2017 |
# ? Feb 10, 2017 21:31 |