|
That shouldn't be possible. Here's some chopped down code showing what the Flask app is doing:code:
code:
|
# ? Feb 11, 2015 22:00 |
|
|
# ? Jun 13, 2024 04:36 |
|
ArcticZombie posted:That shouldn't be possible. Here's some chopped down code showing what the Flask app is doing: How are you running the Flask app and how are you running the standalone? If you're using Flask's app.run(debug=True) then the delay might be down Flask's interactive debugger.
|
# ? Feb 11, 2015 23:19 |
|
Debug mode was enabled, but disabling it only shaves of about 4 seconds so I'm sitting at an average of 16 seconds instead of 20. Still almost double the time. As for the standalone computation, well the code posted is practically all of it, the only part missing is imports. I expect there to be some overhead but it seems a bit extreme.
|
# ? Feb 11, 2015 23:47 |
|
ArcticZombie posted:Debug mode was enabled, but disabling it only shaves of about 4 seconds so I'm sitting at an average of 16 seconds instead of 20. Still almost double the time. As for the standalone computation, well the code posted is practically all of it, the only part missing is imports. I expect there to be some overhead but it seems a bit extreme. How is your memory utilization? High enough that the extra memory overhead from flask/webserver could be causing some swapping?
|
# ? Feb 11, 2015 23:59 |
|
It may be a slowdown because of the switching between the algorithm and the Flask server both running in the same thread? If you spun off a mini-process to compute the result and then brought it back with something like multiprocessing.apply_async it would probably bring it back to normal time.
|
# ? Feb 12, 2015 00:33 |
|
I gave multiprocessing a go and it got the time down to the 9-10 second range, which I'm pretty happy with I guess. Thanks. There's room for further optimization but I'll cross that bridge when I get to it. EDIT: Did some profiling and discovered I had an expensive list opertion being carried out thousands of times. Checking if a move is a duplicate of a move already known, when I can remove duplicates afterwards much faster using an OrderedSet . Time for that same computation is now 2.5 seconds and I can see some more low-hanging fruit. ArcticZombie fucked around with this message at 16:21 on Feb 12, 2015 |
# ? Feb 12, 2015 10:38 |
|
What is an example of when I would use Python code:
Python code:
I guess I don't know what itervalues() gives me that values() does not. EDIT: I am using Python 2.7 if that matters. Jose Cuervo fucked around with this message at 21:05 on Feb 12, 2015 |
# ? Feb 12, 2015 21:02 |
|
Jose Cuervo posted:What is an example of when I would use itervalues gives you an iterator over that dict's values, values gives you a copy of that dict's values If you're just iterating over it and looking at the values then it's functionally identical
|
# ? Feb 12, 2015 21:29 |
|
In Python 2, itervalues() returns an iterator, and .values() returns a list. The iterator loads each value as it's needed, which prevents loading all the values into memory at the same time. If you plan to iterate over the values more than once, you need to convert to a list first, or split it with itertools.tee(). In Python 3, itervalues() is gone, and values() returns an iterator. Python 3's built in functions and methods tend to return iterators when practical. Dominoes fucked around with this message at 21:33 on Feb 12, 2015 |
# ? Feb 12, 2015 21:30 |
|
Dominoes posted:In Python 2, itervalues() returns an iterator, and .values() returns a list. The iterator loads each value as it's needed, which prevents loading all the values into memory at the same time. If you plan to iterate over the values more than once, you need to convert to a list first, or split it with itertools.tee(). Ok great. Now suppose I was iterating over the keys of a dictionary and would be removing keys that fit a certain criteria. In this case I must use Python code:
|
# ? Feb 12, 2015 21:51 |
|
You're right about changing the dictionary being a problem with an iterator: Your example would raise RuntimeError: dictionary changed size during iteration. To avoid this, you could use keys() in Python 2, or list(keys()) in Python 3. Here are two ways to make it work using iterators: Python code:
Python code:
Dominoes fucked around with this message at 22:50 on Feb 12, 2015 |
# ? Feb 12, 2015 21:58 |
|
I'm hacking together a script for work and I'm running into a snag. What I want my script to do is be double-clicked and launched from the desktop. The user types in some input into the console window, then the script will launch an appropriate PDF file. The PDF is launched using a subprocess.call function. My hangup is that the console window for my script stays open, and the script is in a "pause" state, until the user closes the PDF window. How do I go about having the script launch the PDF viewer then close/end itself?
|
# ? Feb 13, 2015 01:37 |
|
Hughmoris posted:I'm hacking together a script for work and I'm running into a snag. How are you launching your PDF viewer? You might trying launching it with something like 'cmd /C viewer.exe filename'. Of course, you would want to break that up into a list and pass it through subprocess.call. You might also try os.startfile(path[, operation]). accipter fucked around with this message at 02:05 on Feb 13, 2015 |
# ? Feb 13, 2015 02:02 |
|
Dominoes posted:You're right about changing the dictionary being a problem with an iterator: Your example would raise RuntimeError: dictionary changed size during iteration. To avoid this, you could use keys() in Python 2, or list(keys()) in Python 3. I significantly prefer the first one for anything that anyone else is going to have to read (not that this is really a complex example) EAT THE EGGS RICOLA fucked around with this message at 02:04 on Feb 13, 2015 |
# ? Feb 13, 2015 02:02 |
|
accipter posted:How are you launching your PDF viewer? You might trying launching it with something like 'cmd /C viewer.exe filename'. Of course, you would want to break that up into a list and pass it through subprocess.call. I am calling it like this: code:
|
# ? Feb 13, 2015 03:17 |
|
Hughmoris posted:I am calling it like this: By launching Acrobat through cmd.exe /C you can essentially fork process, which allows the cmd.exe window to terminate.
|
# ? Feb 13, 2015 03:28 |
|
accipter posted:By launching Acrobat through cmd.exe /C you can essentially fork process, which allows the cmd.exe window to terminate. Could you give me a simple example of what you're talking about using the cmd.exe /c?
|
# ? Feb 13, 2015 04:45 |
|
Dominoes posted:You're right about changing the dictionary being a problem with an iterator: Your example would raise RuntimeError: dictionary changed size during iteration. To avoid this, you could use keys() in Python 2, or list(keys()) in Python 3. This is all true but you should probably not use iterators while removing items from a dictionary
|
# ? Feb 13, 2015 05:05 |
|
Hughmoris posted:I am calling it like this: This is because subprocess.call waits for the program to exit before returning the error code. If you want to continue without waiting for it to finish, you can replace subprocess.call with subprocess.Popen.
|
# ? Feb 13, 2015 09:12 |
|
Edison was a dick posted:This is because subprocess.call waits for the program to exit before returning the error code. This does the job, thanks! I'm running into another issue that seems like it should be very simple but I can't think of an elegant way to do it. My user will input a working date in the format YYYY-MM-DD. Due to the way our files are named, my script needs to do all of its work with the working date + 1. So if the user inputs "2015-02-13" then I need to pass to my functions the date "2015-02-14". Ignoring temporarily the issues if it is the last day of the month, I can't think of a simple way to do that. I guess I could hack away at it with a lot of code to turn "2015-02-13" into a list, then remove the '-', then turn it into an int, then add one to that int, then back to a list, re-insert the '-', then turn all that back into a string. Any ideas on a simpler way to handle that? Hughmoris fucked around with this message at 17:22 on Feb 13, 2015 |
# ? Feb 13, 2015 17:00 |
|
Hughmoris posted:This does the job, thanks! Python code:
|
# ? Feb 13, 2015 17:34 |
|
Thermopyle posted:
Thermopyle, you're a genius. This works perfectly, thank you.
|
# ? Feb 13, 2015 17:57 |
|
Check out the arrow library too. It has clean syntax, and defaults to timezone-aware dates.Python code:
|
# ? Feb 13, 2015 19:48 |
|
Regex issue. How can I use an or statement groups, so that only the part of the or that mathes has its group taken?Python code:
edit: It looks like I can work around this particular example with Python code:
Dominoes fucked around with this message at 17:29 on Feb 15, 2015 |
# ? Feb 14, 2015 00:32 |
|
Dominoes posted:Check out the arrow library too. It has clean syntax, and defaults to timezone-aware dates. Wow, that's pretty simple. I'll take a look at it, thanks.
|
# ? Feb 14, 2015 01:43 |
|
Quick question: Does a shelf act just like a dictionary? For example, if you're going to shelf say some high scores from a game and you wanted to return the highest score along with the name of the player from a shelf would you act on it just like a dictionary? Is a shelfs data type the same as a dictionary?
|
# ? Feb 15, 2015 22:07 |
|
I'm slowly fumbling my way through trying to build a very simple GUI for my Python script, using Tkinter. Its going to be used my non-tech nurses at my hospital, so I'm trying to make it as simple as possible (I'm a nurse too). Is there a way to have the fields auto-tab as they are completed? For instance, when they type in the "month" block, after two digits it would then automatically tab over to the "day" block, and after two more digits it would then jump to the final block. I see it a lot in HTML forms but I'm not if its possible to do that in Tkinter.
|
# ? Feb 15, 2015 22:26 |
|
Hughmoris posted:I'm slowly fumbling my way through trying to build a very simple GUI for my Python script, using Tkinter. Its going to be used my non-tech nurses at my hospital, so I'm trying to make it as simple as possible (I'm a nurse too). I think you'll have to code that up yourself. Sounds like a chore, but you can use set_focus to move the cursor between fields, and then you just need to connect a function to each field to check the current length upon an edit. If 2 digits are present in the most recently edited string, then use set_focus to move to the next widget. Personally, I'm infuriated whenever I encounter data entry fields that auto-tab. If I'm not expecting auto-tab, then suddenly I've unintentionally skipped a field because I always use Tab when entering data into fields anyway. It's one of those features that sounds nice on the surface but just winds up frustrating a lot of users who aren't expecting it.
|
# ? Feb 15, 2015 23:18 |
|
QuarkJets posted:I think you'll have to code that up yourself. Sounds like a chore, but you can use set_focus to move the cursor between fields, and then you just need to connect a function to each field to check the current length upon an edit. If 2 digits are present in the most recently edited string, then use set_focus to move to the next widget. Hmmm, good point. I've never designed any sort of GUI, much less one that would be used by others. I'm just trying to make this as fool proof as possible because I know that the users aren't going to input the Date in the correct format, and the script won't work and they'll say its a piece of crap. Maybe I'm better off figuring out how to do basic error checking on their inputs.
|
# ? Feb 15, 2015 23:30 |
|
Hughmoris posted:Hmmm, good point. I've never designed any sort of GUI, much less one that would be used by others. I'm just trying to make this as fool proof as possible because I know that the users aren't going to input the Date in the correct format, and the script won't work and they'll say its a piece of crap. Yeah, basic error checking would probably be good. You could also auto-fill the current date if you really want to be helpful, unless this is a form that won't usually be using the current date
|
# ? Feb 15, 2015 23:51 |
|
I'm with QuarkJets--the autotab kind of stinks, especially if you screw up and it quickly slings you back forward because whatever condition (length check probably) passed. You could always fire up dateutil.parse and have it guess the format between MM-DD-YYYY, MM-DD-YY, MM/DD/YY, etc.
|
# ? Feb 15, 2015 23:57 |
|
Hed posted:I'm with QuarkJets--the autotab kind of stinks, especially if you screw up and it quickly slings you back forward because whatever condition (length check probably) passed. Thanks for the idea. I used the datetime module to check to see if they entered the date in the format MM/DD/YYYY. If they didn't, it warns them and tells them to put it in correctly. Does anyone have any experience with portable python? Does it work in the sense that its name wound imply? I have a Python script, with a Tkinter GUI, that I want to roll out to some of the nurses that work in my hospital. The computers they use are Windows XP and Windows 7. They all have access to a network "Nurse" folder. I was thinking I could install Portable Python in that network folder and place my script there. then just place a shortcut icon on their desktops. Then when they double click it, it will launch my python script. Am I way off base with this? Any simpler ideas on how to deploy this to make it available on about 20 different computers? I'm way out of my depth on this but I've created something simple that I think will be immensely useful.
|
# ? Feb 16, 2015 03:20 |
|
KICK BAMA KICK posted:Think Python Like a Computer Scientist is very good and written for Python 2; here's the chapter on classes and objects. I was actually just coming to this thread to say thank you to the posters several months ago who recommended this book. I slowly worked my way through it in my free time and finished it today. The exercises were supremely helpful and well-designed and I feel like I understand Python basics extremely well. As a self-taught Python learner, where do I go next? I find that the readily available resources are either targeted toward beginners or experts. There isn't much I can find targeted toward intermediate learners. My goal is to become proficient enough at coding to make it a marketable skill. I am enrolled an and currently taking one of the only Coursera Python courses, which is aimed at complete beginners and quite boring. The others I could find are either significantly above my level or also for complete beginners. Harriet Carker fucked around with this message at 08:32 on Feb 16, 2015 |
# ? Feb 16, 2015 08:28 |
|
Hughmoris posted:Thanks for the idea. I used the datetime module to check to see if they entered the date in the format MM/DD/YYYY. If they didn't, it warns them and tells them to put it in correctly. Unfortunately, I don't think that installing Portable Python to the network folder will be enough. Each Windows computer won't know what to do with a .py file unless it has associated that file extension with a Python executable. The admin-independent way of doing this would be to have each user log in to each computer, double click on the script, and then navigate to your Portable Python's python.exe. But it would be better to faster and easier to just install Python on all of those computers Other users have had some experience with cx_freeze, with just lets you turn your Python code into an executable. This might actually be the easiest thing to do in your case unless you can get your IT department to install Python on all of your systems
|
# ? Feb 16, 2015 08:32 |
|
dantheman650 posted:I was actually just coming to this thread to say thank you to the posters several months ago who recommended this book. I slowly worked my way through it in my free time and finished it today. The exercises were supremely helpful and well-designed and I feel like I understand Python basics extremely well. I'm a big fan of Peter Norvig's course on Udacity and I think it's just right for your level: https://www.udacity.com/course/cs212
|
# ? Feb 16, 2015 08:46 |
|
dantheman650 posted:I was actually just coming to this thread to say thank you to the posters several months ago who recommended this book. I slowly worked my way through it in my free time and finished it today. The exercises were supremely helpful and well-designed and I feel like I understand Python basics extremely well. Think of a project and build it with the help of Google, this thread, stack overflow, etc. Something like a script to organize your download folder, or fetch your favorite stock price and insert it into a spreadsheet, or...
|
# ? Feb 16, 2015 17:54 |
|
QuarkJets posted:Unfortunately, I don't think that installing Portable Python to the network folder will be enough. Each Windows computer won't know what to do with a .py file unless it has associated that file extension with a Python executable. The admin-independent way of doing this would be to have each user log in to each computer, double click on the script, and then navigate to your Portable Python's python.exe. But it would be better to faster and easier to just install Python on all of those computers Thanks for the ideas. I tried to look at py2exe last night but got pretty confused. I'm wondering how the conversion to exe will work since I'm using quite a few of additional modules such as Tkinter and pyPdf. I'll see if I can figure out cx_freeze this evening.
|
# ? Feb 16, 2015 18:51 |
|
You've stumbled across one of Python's biggest weaknesses. Let me know if you run into trouble configuring cx_freeze. Another approach is making a webapp using Flask or Django.
|
# ? Feb 16, 2015 18:52 |
|
Symbolic Butt posted:I'm a big fan of Peter Norvig's course on Udacity and I think it's just right for your level: https://www.udacity.com/course/cs212 Thanks for this! I like the Udacity layout better than Coursera and I enjoy the ability to study at my own pace. The first lesson is making a poker program, which, coincidentally, is one of the last exercises in Think Python, so that seems like a good sign this will be appropriate for my level. I'll give it a go. Thermopyle posted:Think of a project and build it with the help of Google, this thread, stack overflow, etc. This is what I was trying to do but I couldn't think of any great ideas. I tend to learn better when there's a directed goal someone else creates for me, but after I finish this course it seems like working on my own projects will be the best way to get better. Thanks!
|
# ? Feb 17, 2015 01:05 |
|
|
# ? Jun 13, 2024 04:36 |
|
Dominoes posted:You've stumbled across one of Python's biggest weaknesses. Let me know if you run into trouble configuring cx_freeze. I've thought about making a webapp but when I looked at Django, I was 100% lost. I don't think I have a decent enough grasp on Python yet to delve into Django. I might take you up on your offer with cx_freeze though. Going to try and get some time to dive into it.
|
# ? Feb 17, 2015 02:54 |