|
Emacs Headroom posted:A few more advantages of notebooks (a non-exhaustive list): Oh come on, really? "Save script, run script, look at plots" is one keystroke in any competent IDE I feel like I'm watching one of those goofy infomercials where they try to sell you a product by showing people getting flummoxed by basic tasks, with the promise that everything will be so much easier if you just buy this special bread knife or some sort of human grazing muzzle or whatever (I'm not trying to poke fun, the superfluous steps in your example just really gave me that infomercial vibe and I loving love infomercial GIFs)
|
# ? Sep 30, 2015 09:13 |
|
|
# ? May 9, 2024 00:56 |
|
Maybe if you look at it like this ... A paper certainly has some value in communicating the results of an analysis. Now imagine a format which has all of the information in the paper, but instead of there only being a description of the code, there is the actual code, right at your fingertips. And you can not only look at the code and read it along with the output it gave, you can also, depending on a few circumstances, re-run specific analysis stages under manipulation of certain parameters, or do follow-up analyses building on the total output. An IDE is for developing. The notebook is for developing, visualising, communicating/presenting, all at once. I don't think anybody will argue IDEs are not better at the single thing they do, but I'd be surprised if you would really claim notebooks are not really good at the other things they do, and that there are scenarios where the combination of these has some nice synergies.
|
# ? Sep 30, 2015 09:53 |
|
Cingulate posted:Maybe if you look at it like this ... Yeah, I agree with everything in your post. Notebooks are the "jack of all trades" utility for a scientific analysis, basically.
|
# ? Sep 30, 2015 09:57 |
|
I accept it was dumb to say all science in Python should be done in the notebook. The statement reflects my specific circumstances.
|
# ? Sep 30, 2015 10:22 |
|
I have another Qt question. I have enabled Drag and Drop so that a user can re-arrange rows and columns in a TableView. How do I commit these changes to the TableModel? Everything that I can find on google about editing a table has to do with editing individual cells, which requires a Delegate. I don't need that. I just want to change the order of the rows/columns. The fact that no one else has asked this question to StackExchange makes me think it's something very basic that I'm missing.
|
# ? Oct 1, 2015 16:28 |
|
Im currently learning Python through a coursera course for data analysis, but one of my reasons for learning Python over my last attempt at learning R was because of Python's seemingly bigger use for automating tasks and other stuff (while R seemed to be much more on hardcore stats and data analysis only). One task I have that I want to tackle automating is where, I'll get a dump of .docx files in a networked folder. They are all formatted in a specific style with usually the title written in all caps with an underscore, and then a couple paragraphs, and then a signature block at the bottom. I have to take these word documents, go into an Excel spreadsheet thats formatted like a documents log, and manually copy and paste the title into a column labelled titles, copy the body of the work into a column for body, dates, times etc. and do these for each file. Basically I am creating a mini-database of all these reports by hand. Yes I realize that this is an incredibly stupid process that ought to be fixed at a level above mine, but at the same time Im interested in learning more Python automation to teach myself to work within these environments that are very computer-averse. Now I know that .docx files are essentially zipped files of XML based formatted text, so that there should be a library or function I can use to read and automate the extraction of the Headers, body, etc., but then also I need a way for it to populate a .CSV or Excel file.
|
# ? Oct 3, 2015 07:19 |
|
Sounds pretty straightforward to me. Check out docx2txt for dumping the raw text to an ascii format. From there it's all a matter of intelligently extracting the pieces that you want, but it sounds like you have some good ideas of how to do this. Once you've identified what everything is, dumping it to a CSV is extremely easy
|
# ? Oct 3, 2015 07:35 |
|
QuarkJets posted:Sounds pretty straightforward to me. Check out docx2txt for dumping the raw text to an ascii format. From there it's all a matter of intelligently extracting the pieces that you want, but it sounds like you have some good ideas of how to do this. Once you've identified what everything is, dumping it to a CSV is extremely easy re: CSV. There the builtin 'csv'. I use it all the time and it's very easy to use. Or there's always the option to write it out as a standard file just separating the elements with a ',' and manually adding a '\r\n' at the end of each row. But that seems like a lot of work compared to just using csv.
|
# ? Oct 3, 2015 08:10 |
|
I'm not sure if this has been asked before, but I'm not sure exactly what I would be searching for. When I have a list of things and I iterate through it and remove things, I notice that my for loops don't iterate over the whole list. Is it specifically because I'm performing a remove on the same list I'm iterating over? Example: code:
code:
code:
code:
1. Am I right in my understanding? 2. I don't see any problems in the results I get when I do this (except weird logs), but is there a better way to iterate over the list and remove items midway through? Superdawg fucked around with this message at 19:18 on Oct 4, 2015 |
# ? Oct 4, 2015 19:08 |
|
Superdawg posted:Is it specifically because I'm performing a remove on the same list I'm iterating over? Yeah, don't modify lists while iterating over them. The docs explain what's happening: quote:Note: There is a subtlety when the sequence is being modified by the loop (this can only occur for mutable sequences, i.e. lists). An internal counter is used to keep track of which item is used next, and this is incremented on each iteration. When this counter has reached the length of the sequence the loop terminates. This means that if the suite deletes the current (or a previous) item from the sequence, the next item will be skipped (since it gets the index of the current item which has already been treated). Likewise, if the suite inserts an item in the sequence before the current item, the current item will be treated again the next time through the loop. This can lead to nasty bugs that can be avoided by making a temporary copy using a slice of the whole sequence, e.g.: code:
|
# ? Oct 4, 2015 19:29 |
|
Makes sense. Thanks for the help. I have made the adjustment and confirmed that the issue does not show anymore. code:
code:
|
# ? Oct 4, 2015 19:37 |
|
It's more idiomatic to make a new list with all the things you want to keep, instead of removing the things you don't want from the old list.
|
# ? Oct 4, 2015 19:56 |
|
Look into filter.
|
# ? Oct 4, 2015 20:27 |
|
Superdawg posted:Makes sense. Thanks for the help. I've always used this to prune items from my list: Python code:
|
# ? Oct 4, 2015 21:32 |
|
In the specific case of getting rid of duplicates you can do list(set(some_list))
|
# ? Oct 4, 2015 21:54 |
|
My use case is to eventually eliminate everything in the list, but I have to wait until each of the items returns the right state. Until then, I need to keep looping.
|
# ? Oct 4, 2015 22:35 |
|
Superdawg posted:My use case is to eventually eliminate everything in the list, but I have to wait until each of the items returns the right state. Until then, I need to keep looping. code:
|
# ? Oct 4, 2015 23:17 |
|
QuarkJets posted:Sounds pretty straightforward to me. Check out docx2txt for dumping the raw text to an ascii format. From there it's all a matter of intelligently extracting the pieces that you want, but it sounds like you have some good ideas of how to do this. Once you've identified what everything is, dumping it to a CSV is extremely easy Yeah I have an idea of how I want to do it, but Im still pretty new to Python. Any tips or resources about how I should go about extracting those pieces, and then dumping them into an excel?
|
# ? Oct 4, 2015 23:36 |
|
Quick question. I have a piece of code in a psychology experiment that goes like this:code:
Fixation cross (1s) -> WORD (500ms) -> Response window (2s) During the response window, both while the word is still on screen and for 2s afterward, the participant's response time is recorded via verbal input using a microphone. The piece of the code I am interested in, however, is this: code:
If keypress in time window, then code 'acc_resp' as 1 If no keypress in time window, code 'acc_resp' as 0 That way, the trials will advance normally, without pausing for input, but I'm still able to 'tag' bad trials if need be. I'd like for the program to 'listen' for this key input for the same window it's 'listening' for mix input. How might I go about doing this, or would it require a serious re-write of the code?
|
# ? Oct 5, 2015 01:37 |
|
Poizen Jam posted:Basically, after each trial, the program pauses until the experimenter inputs a code on the numpad- 1 for 'correct', 2 for 'incorrect', 3 for 'spoils'. Given the fact 90%+ of trials are answered correctly, this is an unnecessary, attention demanding task. Ideally, what I'd like to occur is something like this: Right, so you already have the block that listens for a key press. Just grab the time before the keypress prompt and after the key has been pressed, then compare those Python code:
|
# ? Oct 5, 2015 02:53 |
|
Melian Dialogue posted:Yeah I have an idea of how I want to do it, but Im still pretty new to Python. Any tips or resources about how I should go about extracting those pieces, and then dumping them into an excel? This is mostly an implementation question, there are any number of good answer and they're all going to depend on you having a good understanding of your inputs. Let's say that your inputs all look something like this: Python code:
After that, you can immediately read the text file with open(). Python code:
First, let's remove any lines that are empty Python code:
Python code:
All together: Python code:
QuarkJets fucked around with this message at 03:41 on Oct 5, 2015 |
# ? Oct 5, 2015 03:38 |
|
Gothmog1065 posted:Okay, more of a theoretical question than a straight code question, but I'm still working on the Skynet game I started (Here is my ultimate revised code and Here is the game itself). Okay, update on this, here's what I've gotten so far (Without all my notes): code:
e: I haven't tested the code yet, so there might be some minor errors in there. Gothmog1065 fucked around with this message at 20:02 on Oct 5, 2015 |
# ? Oct 5, 2015 19:59 |
|
QuarkJets posted:Right, so you already have the block that listens for a key press. Just grab the time before the keypress prompt and after the key has been pressed, then compare those I'm not terribly worried about system time changing. You'll notice other code depends on elapsed time as well. But will this allow Python to 'listen' for a key press during the same window it's listening for a vocal response, or is this still executed afterward? Referring back to the design Fixation cross (1s) -> Stimulus (500ms) -> Response Window/blank screen (2s) The vocal response window is 2.5 s (the bolded part- from the onset of the stimulus to the end of the response window), and I want the key press accepted at any point during this same window, else it simply moves onto the next trial (at the end of the 2s 'response window'- new trial, back to fixation cross) and codes a 0. Correct me if I'm wrong, but the way you have it coded- doesn't it still append itself to the end of the trial like- Fixation cross (1s) -> Stimulus (500ms) -> Vocal Response Window/blank screen (2s) -> Key Press window (arbitrary time, code 0 if no response)
|
# ? Oct 6, 2015 13:20 |
|
I think you want to use getKeys() instead, which doesn't block (and has a timeStamped flag). If you use core.wait with getKeys, make sure to constantly poll. Also psychopy has the worst docs.
|
# ? Oct 6, 2015 13:34 |
|
Cingulate posted:I think you want to use getKeys() instead, which doesn't block (and has a timeStamped flag). The 'get keys' function is likely simple enough to look up, but what do you mean by 'constantly poll', and how does core wait interrupt it? Edit: Also, is there a simple way to 'pause' a Python script? As in, when I press space, it halts script execution wherever it may be and resumes when I hit space again? PoizenJam fucked around with this message at 16:38 on Oct 6, 2015 |
# ? Oct 6, 2015 14:31 |
|
Poizen Jam posted:The 'get keys' function is likely simple enough to look up, but what do you mean by 'constantly poll', and how does core wait interrupt it? quote:If you want to obtain key-presses during the wait, be sure to use pyglet and to hogCPU for the entire time, and then call psychopy.event.getKeys() after calling wait() So you'd do core.wait(secs, hogCPUperiod=some_time_here) You only get accurate time within the period where you hog the CPU.
|
# ? Oct 6, 2015 19:27 |
|
ahmeni posted:Luckily I had my Jupyter notebook handy to calculate the results of this plague: Seeing Bokeh plots in the wild always makes my day.
|
# ? Oct 7, 2015 04:20 |
|
Is there an easy way (without doing a whole lot of major importiong beyond sys and math) to iterate over a 2 dimensional list (think a list of coordinates in tuples)? Example: [(0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7), (0, 8), (0, 9), (0, 10), (0, 11), (0, 12), (0, 13), (0, 14), (0, 15), (0, 16), (0, 17), (1, 2), (2, 3), (3, 4), (3, 34), (4, 5), (4, 33), (5, 6), (6, 7), (7, 8), (8, 9), (9, 10), (10, 11), (11, 12), (12, 13), (13, 14), (14, 15), (15, 16), (16, 17), (17, 1), (18, 19), (18, 20), (18, 21), (18, 22), (18, 23), (18, 24), (18, 25), (18, 26), (18, 27), (19, 20), (20, 21), (21, 22), (22, 23), (23, 24), (24, 25), (25, 26), (26, 27), (27, 19), (28, 29), (28, 30), (28, 31), (28, 32), (28, 33), (28, 34), (28, 35), (28, 36), (29, 21), (29, 30), (30, 31), (31, 32), (32, 33), (33, 34), (34, 35), (35, 2), (35, 23), (35, 36), (36, 22), (36, 29), (37, 1), (37, 2), (37, 23), (37, 24), (37, 35)] Iterating over that list and seeing how many times say "0" exists at all within those tuple pairs (17 I think).
|
# ? Oct 8, 2015 19:39 |
|
Gothmog1065 posted:Iterating over that list and seeing how many times say "0" exists at all within those tuple pairs (17 I think). Python code:
|
# ? Oct 8, 2015 19:44 |
|
KICK BAMA KICK posted:
Thanks. I really need to get into writing quick for loops like that.
|
# ? Oct 8, 2015 19:56 |
|
Gothmog1065 posted:Thanks. I really need to get into writing quick for loops like that. comprehensions, not for loops
|
# ? Oct 8, 2015 20:02 |
|
Hi folks. I'm interested in coding a productivity app for personal use and as a learning project. I'm not a professional programmer, but I have some very basic python experience, so I'd like to use python as the starting point. As an end goal, I'd like my program to track a list of tasks and catalogue them in lots of different ways, with the ability to look at my workload through different 'lenses' and group them differently according to which lens I'm using. I'd be grateful for some broad advice about what software/frameworks I should be using to code an app like this, so I can direct my learning in the right direction. I really have no experience, but I'm thinking I'll need some sort of database to track the tasks and assign attributes to them as well as some software to provide the GUI. My only real criteria for the GUI is something that doesn't look like crap and it would be a bonus if it were able to be cross-platform (Windows and Linux). Sorry for the unavoidably vague questions!
|
# ? Oct 8, 2015 20:14 |
|
Prince John posted:I'd be grateful for some broad advice about what software/frameworks I should be using to code an app like this, so I can direct my learning in the right direction. I really have no experience, but I'm thinking I'll need some sort of database to track the tasks and assign attributes to them as well as some software to provide the GUI. My only real criteria for the GUI is something that doesn't look like crap and it would be a bonus if it were able to be cross-platform (Windows and Linux). If you have any inclination towards or experience with websites, a webapp might be the way to go, more relevant to almost anything else than some Python-specific GUI kit, completely cross-platform, fits very well with Python, and lets you learn Python, web frameworks, and basic web stuff all in one go. As a downside, you have to learn all of those things in one go.
|
# ? Oct 9, 2015 03:18 |
|
Microsoft OneDrive dev team just released this today: https://github.com/OneDrive/onedrive-sdk-python
|
# ? Oct 9, 2015 03:24 |
|
OnceIWasAnOstrich posted:If you have any inclination towards or experience with websites, a webapp might be the way to go, more relevant to almost anything else than some Python-specific GUI kit, completely cross-platform, fits very well with Python, and lets you learn Python, web frameworks, and basic web stuff all in one go. As a downside, you have to learn all of those things in one go. I was idly wondering this. My only reluctance to go the web app route was that I might want to use it at work eventually, and probably wouldn't be permitted to run a local webserver on my machine. Would you go for django + sqlite as a starting point?
|
# ? Oct 9, 2015 23:50 |
|
Prince John posted:I was idly wondering this. My only reluctance to go the web app route was that I might want to use it at work eventually, and probably wouldn't be permitted to run a local webserver on my machine. I'm not sure what you mean by "a local webserver", but in case you weren't aware, an app like this can be served straight from python, basic python has an HTTP server built-in, and the different frameworks like Django, have their own built-in webserver. In other words, you don't have to actually install a "real" webserver like Apache, which you might be thinking you have to do... Django + sqlite is a fine choice.
|
# ? Oct 10, 2015 00:10 |
|
Prince John posted:I was idly wondering this. My only reluctance to go the web app route was that I might want to use it at work eventually, and probably wouldn't be permitted to run a local webserver on my machine. Like Themopyle aludes to, you won't need any more permissions to run a Python webapp than you would any other Python script on a local machine, so if they are fine with you running/programming arbitrary programs on your local machine you should be good to go. Django is probably a good route to go since you will likely have a bunch of data that should fit the normal relational database usecases. If you find it to be difficult to match up to how you want to store data or for some reason want to more directly implement your data management stuff you can use simpler frameworks like Flask or CherryPy. Sqlite is also ideal, for the most part in Python you should be using a database library that will abstract out all of your database interactions so you could trivially switch from Sqlite to any other SQL implementation with no effort, not that you would need to for personal use.
|
# ? Oct 10, 2015 04:11 |
|
This my first foray into scraping Javascript pages, and I'm trying to use dryscrape which is based on QT webkit. If everything is working correctly I should be triggering a "download file" popup. How do I catch the file the site is trying to send me, ideally into a string but I would be happy reading it again off the local file system.
|
# ? Oct 10, 2015 07:17 |
|
Thermopyle posted:I'm not sure what you mean by "a local webserver", but in case you weren't aware, an app like this can be served straight from python, basic python has an HTTP server built-in, and the different frameworks like Django, have their own built-in webserver. In other words, you don't have to actually install a "real" webserver like Apache, which you might be thinking you have to do... Thanks all for the advice everyone. I wasn't aware of the distinctions between running something like Apache and what was proposed, so that's very helpful. I have permission to run arbitrary programs on the computer so that shouldn't be a problem.
|
# ? Oct 10, 2015 12:02 |
|
|
# ? May 9, 2024 00:56 |
|
i'm trying to make a palindrome tester, what am i doing wrong here?code:
i managed to get it to work much more cleanly with a for code:
|
# ? Oct 13, 2015 08:08 |