Q_Id
int64
337
49.3M
CreationDate
stringlengths
23
23
Users Score
int64
-42
1.15k
Other
int64
0
1
Python Basics and Environment
int64
0
1
System Administration and DevOps
int64
0
1
Tags
stringlengths
6
105
A_Id
int64
518
72.5M
AnswerCount
int64
1
64
is_accepted
bool
2 classes
Web Development
int64
0
1
GUI and Desktop Applications
int64
0
1
Answer
stringlengths
6
11.6k
Available Count
int64
1
31
Q_Score
int64
0
6.79k
Data Science and Machine Learning
int64
0
1
Question
stringlengths
15
29k
Title
stringlengths
11
150
Score
float64
-1
1.2
Database and SQL
int64
0
1
Networking and APIs
int64
0
1
ViewCount
int64
8
6.81M
1,424,398
2009-09-14T23:28:00.000
1
1
0
1
python,python-idle
35,376,000
11
false
0
0
For OS X: Open a new finder window,then head over to applications. Locate your Python application. (For my mac,it's Python 3.5) Double click on it. Right click on the IDLE icon,show package contents. Then go into the contents folder,then resources. Now,this is the important part: (Note: You must be the administrator or have the administrator's password for the below to work) Right click on the idlemain.py,Get Info. Scroll all the way down. Make sure under the Sharing & Permissions tab,your "name"(Me) is on it with the privilege as Read & Write. If not click on the lock symbol and unlock it. Then add/edit yourself to have the Read & Write privilege. Lastly,as per Ned Deily's instructions,edit the line: os.chdir(os.path.expanduser('~/Documents')) with your desired path and then save the changes. Upon restarting the Python IDLE,you should find that your default Save as path to be the path you've indicated.
8
9
0
Does anyone know where or how to set the default path/directory on saving python scripts prior to running? On a Mac it wants to save them in the top level ~/Documents directory. I would like to specify a real location. Any ideas?
Default save path for Python IDLE?
0.01818
0
0
28,611
1,424,398
2009-09-14T23:28:00.000
2
1
0
1
python,python-idle
53,340,799
11
false
0
0
In Windows 10+, click the Windows Start button, then type idle, and then right-click on the IDLE desktop app and open the file location. This should bring you to the Start Menu shortcuts for Python, and you'll find a shortcut to IDLE there. Right-click on the IDLE shortcut and select properties. Set the "Start in" directory to be where you want default save path to be.
8
9
0
Does anyone know where or how to set the default path/directory on saving python scripts prior to running? On a Mac it wants to save them in the top level ~/Documents directory. I would like to specify a real location. Any ideas?
Default save path for Python IDLE?
0.036348
0
0
28,611
1,424,398
2009-09-14T23:28:00.000
1
1
0
1
python,python-idle
43,900,532
11
false
0
0
I am using windows 7 and by going to Start-> IDLE(Python 3.6 32-bit) The click on properties and then in the shortcut tab go to Start in and entering the desired path worked for me kindly note if IDLE is open and running while you do this you'll have to shut it down and restart it for this to work
8
9
0
Does anyone know where or how to set the default path/directory on saving python scripts prior to running? On a Mac it wants to save them in the top level ~/Documents directory. I would like to specify a real location. Any ideas?
Default save path for Python IDLE?
0.01818
0
0
28,611
1,424,398
2009-09-14T23:28:00.000
2
1
0
1
python,python-idle
5,161,261
11
false
0
0
It seems like you can get idle into the directory you want if you run any module from that directory. I had previously tried opening idlemain.py through the path browser. I was able to open and edit the file, but it seemed like I wasn't able to save my modifications. I'm just glad to hear other people are having this problem. I just thought I was being stupid.
8
9
0
Does anyone know where or how to set the default path/directory on saving python scripts prior to running? On a Mac it wants to save them in the top level ~/Documents directory. I would like to specify a real location. Any ideas?
Default save path for Python IDLE?
0.036348
0
0
28,611
1,424,398
2009-09-14T23:28:00.000
1
1
0
1
python,python-idle
1,424,722
11
false
0
0
On Windows (Vista at least, which is what I'm looking at here), shortcut icons on the desktop have a "Start in" field where you can set the directory used as the current working directory when the program starts. Changing that works for me. Anything like that on the Mac? (Starting in the desired directory from the command line works, too.)
8
9
0
Does anyone know where or how to set the default path/directory on saving python scripts prior to running? On a Mac it wants to save them in the top level ~/Documents directory. I would like to specify a real location. Any ideas?
Default save path for Python IDLE?
0.01818
0
0
28,611
1,424,398
2009-09-14T23:28:00.000
0
1
0
1
python,python-idle
1,424,502
11
false
0
0
If you locate the idlelib directory in your Python install, it will have a few files with the .def extension. config-main.def has instructions on where to put the custom config files. However, looking through these I did not find any configurable paths (your install may vary). Looks like you might need to crack open the editor code to alter it.
8
9
0
Does anyone know where or how to set the default path/directory on saving python scripts prior to running? On a Mac it wants to save them in the top level ~/Documents directory. I would like to specify a real location. Any ideas?
Default save path for Python IDLE?
0
0
0
28,611
1,424,398
2009-09-14T23:28:00.000
1
1
0
1
python,python-idle
1,424,507
11
false
0
0
If you open a module, that sets the default working directory. Start IDLE. File -> Open to open your file. And set the current working directory.
8
9
0
Does anyone know where or how to set the default path/directory on saving python scripts prior to running? On a Mac it wants to save them in the top level ~/Documents directory. I would like to specify a real location. Any ideas?
Default save path for Python IDLE?
0.01818
0
0
28,611
1,424,534
2009-09-15T00:24:00.000
2
0
1
0
python
1,424,582
2
true
0
0
The main question I would think about is how much of your library would return numpy objects? If its pervasive I would go with directly returning a numpy as your so tied to numpy you might as well make it explicit. Plus it will probably make it easier to use other numpy based libraries. If on the other hand you only have a few methods that would return numpy I would either go with the numpy like object or a list, probably the numpy like object.
1
1
0
Common scenario: I have a library that uses other libraries. For example, a math library (let's call it foo) that uses numpy. Functions of foo can either: return a numpy object (either pure or an inherited reimplementation) return a list return a foo-implemented object that behaves like numpy (performing delegation) The three solutions can be also restated as: foo passes through the internally used object, clearly stating that its library dependency is also a API dependency (since it returns objects obeying the interface of the numpy library) foo makes use of a common subset of objects that are part of the basis of the language. foo completely hides what it uses internally. Nothing about the underlying libraries escapes from the foo library to the client code. We are of course in a pros-cons scenario. Transparent or opaque? strong coupling with the underlying tools or not? I know the drill but I am in the process of having to do this choice, and I want to share opinions before taking a decision. Suggestions, ideas, personal experience are greatly appreciated.
exposing or hiding objects of dependencies?
1.2
0
0
147
1,424,593
2009-09-15T00:47:00.000
0
1
0
0
php,python,ipc
1,424,687
2
false
0
0
You could look at shared memory or named pipes, but I think there are two more likely options, assuming at least one of these languages is being used for a webapp: A. Use your database's atomicity. In python, begin a transaction, put a message into a table, and end the transaction. From php, begin a transaction, take a message out of the table or mark it "read", and end the transaction. Make your PHP and/or python self-aware enough not to post the same messages twice. Voila; reliable (and scaleable) IPC, using existing web architecture. B. Make your webserver (assuming as webapp) capable of running both php and python, locking down any internal processes to just localhost access, and then call them using xmlrpc or soap from your other language using standard libraries. This is also scalable, as you can change your URLs and security lock-downs later.
1
1
0
I have a python program which starts up a PHP script using the subprocess.Popen() function. The PHP script needs to communicate back-and-forth with Python, and I am trying to find an easy but robust way to manage the message sending/receiving. I have already written a working protocol using basic sockets, but it doesn't feel very robust - I don't have any logic to handle dropped messages, and I don't even fully understand how sockets work which leaves me uncertain about what else could go wrong. Are there any generic libraries or IPC frameworks which are easier than raw sockets? ATM I need something which supports Python and PHP, but in the future I may want to be able to use C, Perl and Ruby also. I am looking for something robust, i.e. when the server or client crashes, the other party needs to be able to recover gracefully.
Easy, Robust IPC between Python and PHP
0
0
1
2,322
1,424,734
2009-09-15T01:49:00.000
1
0
0
0
python,pygame,alphablending
1,429,443
2
true
0
1
Considering the pygame docs I would say "no, there is no global way to disable alpha". However there are at least two 'local' ways to do it: First would be to subclass pygame.Surface and provide your own implementation of set_alpha which in turn could honor your global alpha settings. Second one is a bit more tricky as it depends on the pixel-format in use. To quote the pygame docs: Surface.set_alpha set the alpha value for the whole surface [...] This value is different than the per pixel Surface alpha. If the Surface format contains per pixel alphas, then this alpha value will be ignored. If the Surface contains per pixel alphas, setting the alpha value to None will disable the per pixel transparency. [...] With this you could provide two sets of textures: one with an opaque (per-pixel) alpha channel which will overwrite all your calls to set_alpha() one which has no per-pixel alpha and thus will honor your set_alpha() Hope this will help!
1
1
0
I have a computer game I'm working on, and I'm wanting to give the user an option to turn off alpha compositing for speed purposes. Rather than doing checks everywhere, does Pygame have a global option to say "Don't use alpha" such that it would just ignore all my calls to set_alpha and the likes?
Turn off Pygame alpha
1.2
0
0
570
1,425,149
2009-09-15T04:42:00.000
1
0
0
0
python,gps,geocoding,reverse-geocoding
1,425,355
6
false
0
0
If you can get hold of state boundaries as polygons (for example, via OpenStreetMap), determining the current state is just a point-in-polygon test. If you need address data, an offline solution would be to use Microsoft Mappoint.
2
14
0
I am working on an application where one of the requirements is that I be able to perform realtime reverse geocoding operations based on GPS data. In particular, I must be able to determine the state/province to which a latitude, longitude pair maps and detect when we have moved from one state/province to another. I have a couple ideas so far but wondered if anyone had any ideas on either of the following: What is the best approach for tackling this problem in an efficient manner? Where is a good place to find and what is the appropriate format for North American state/province boundaries As a starter, here are the two main ideas I have: Break North America into a grid with each rectangle in the grid mapping to a particular state province. Do a lookup on this table (which grows quickly the more precise you would like to be) based on the latitude and then the longitude (or vice versa). Define polygons for each of the states and do some sort of calculation to determine in which polygon a lat/lon pair lies. I am not sure exactly how to go about this. HTML image maps come to mind as one way of defining the bounds for a state/province. I am working in python for the interested or those that might have a nice library they would like to suggest. To be clear... I do not have web access available to me, so using an existing reverse geocoding service is not an option at runtime
Reverse Geocoding Without Web Access
0.033321
0
0
12,745
1,425,149
2009-09-15T04:42:00.000
0
0
0
0
python,gps,geocoding,reverse-geocoding
1,425,312
6
false
0
0
I have a database with all of this data and some access tools. I made mine from the census tiger data. I imagine it'd basically be an export of my database to sqlite and a bit of code translation.
2
14
0
I am working on an application where one of the requirements is that I be able to perform realtime reverse geocoding operations based on GPS data. In particular, I must be able to determine the state/province to which a latitude, longitude pair maps and detect when we have moved from one state/province to another. I have a couple ideas so far but wondered if anyone had any ideas on either of the following: What is the best approach for tackling this problem in an efficient manner? Where is a good place to find and what is the appropriate format for North American state/province boundaries As a starter, here are the two main ideas I have: Break North America into a grid with each rectangle in the grid mapping to a particular state province. Do a lookup on this table (which grows quickly the more precise you would like to be) based on the latitude and then the longitude (or vice versa). Define polygons for each of the states and do some sort of calculation to determine in which polygon a lat/lon pair lies. I am not sure exactly how to go about this. HTML image maps come to mind as one way of defining the bounds for a state/province. I am working in python for the interested or those that might have a nice library they would like to suggest. To be clear... I do not have web access available to me, so using an existing reverse geocoding service is not an option at runtime
Reverse Geocoding Without Web Access
0
0
0
12,745
1,425,162
2009-09-15T04:48:00.000
1
0
1
0
python,data-structures,matrix
1,425,181
4
false
0
0
You only need to store the lower triangle of the matrix. Typically this is done with one n(n+1)/2 length list. You'll need to overload the __getitem__ method to interpret what the entry means.
2
1
1
I'm looking to create a 2d matrix of integers with symmetric addressing ( i.e. matrix[2,3] and matrix[3,2] will return the same value ) in python. The integers will have addition and subtraction done on them, and be used for logical comparisons. My initial idea was to create the integer objects up front and try to fill a list of lists with some python equivalent of pointers. I'm not sure how to do it, though. What is the best way to implement this, and should I be using lists or another data structure?
Symmetrically adressable matrix
0.049958
0
0
247
1,425,162
2009-09-15T04:48:00.000
2
0
1
0
python,data-structures,matrix
1,425,305
4
false
0
0
You're probably better off using a full square numpy matrix. Yes, it wastes half the memory storing redundant values, but rolling your own symmetric matrix in Python will waste even more memory and CPU by storing and processing the integers as Python objects.
2
1
1
I'm looking to create a 2d matrix of integers with symmetric addressing ( i.e. matrix[2,3] and matrix[3,2] will return the same value ) in python. The integers will have addition and subtraction done on them, and be used for logical comparisons. My initial idea was to create the integer objects up front and try to fill a list of lists with some python equivalent of pointers. I'm not sure how to do it, though. What is the best way to implement this, and should I be using lists or another data structure?
Symmetrically adressable matrix
0.099668
0
0
247
1,426,272
2009-09-15T10:05:00.000
0
0
0
0
python,design-patterns,architecture
1,426,368
2
false
1
0
You may be operating under a mis-conception: pickles don't include the code from classes that are pickled. You can add methods to your data structures, and it will not increase the size of your pickles. This is a common misunderstanding about pickles. They don't include code.
1
1
0
Please consult me with your opinions on the following topic: I have a model - a structure of the objects. Such as: Event, containing participants Current task Assignee of each task The model is going to be pickled on the server and transferred over the network to the client GUI application. Because of the pickle I'd want to keep the model classes as simple as possible (i.e. just simple classes with data fields only, no any single method inside). As a result I can't create signals (such as OnUpdate) on the model objects. Sometimes the server will send model updates. Such as "Task text changed". When the update is applied, I need it to be reflected in the UI. In the case of task text change it shall be change of the label in the UI. I'd want only related controls to be changed, so the whole UI update is not the best solution. On the other hand, would not like to traverse the whole model in the search of changes - that would be too resource intensive. So, what is the best pattern of notifying the UI about changes on the plain data structures?
Live UI update of model changes when the model contains plain data structures only
0
0
0
108
1,426,779
2009-09-15T12:08:00.000
1
0
0
1
python,google-app-engine,proxy
1,427,324
3
false
1
0
SOCKS is not an HTTP-based protocol, so it's not possible to write a SOCKS proxy on App Engine. Edit: Note I wrote the above when you were specifically referring to a SOCKS proxy. Regarding general HTTP proxy servers, you can't really do that on App Engine, either, because proxies need to be able to accept requests for any hostname; your App Engine app will only accept requests for the hosts you're serving off it. You could write an 'anonymizer' type interface on App Engine, but it's not a true proxy, because it will require rewriting URLs to work.
1
2
0
I am looking for a basic open source http proxy server for Google App Engine. Preferably written in Python. Any suggestions?
Proxy for Google App Engine
0.066568
0
0
5,503
1,430,517
2009-09-16T01:51:00.000
0
0
0
0
python,django,multithreading
1,430,541
2
false
1
0
What are you using to restart django? I'd put something in that script to look for process id's in the socket file(s) and kill those before starting django. Alternatively, you could be very heavy handed and just run something like 'pkill -9 *django*' before your django startup sequence.
1
0
0
I'm running Django, and I'm creating threads that run in parallel while Django runs. Those threads sometimes run external processes that block while waiting for external input. When I restart Django, those threads that are blocking while awaiting external input sometimes persist through the restart, and further they have and keep open Port 8080 so Django can't restart. If I knew when Django was restarting, I could kill those threads. How can I tell when Django is restarting so that I can kill those threads (and their spawn). It wasn't obvious from django.utils.autoreload where any hooks may be to tell when a restart is occurring. Is there an alternative way to kill these threads when Django starts up? Thanks for reading. Brian
Kill sub-threads when Django restarts?
0
0
0
1,029
1,431,495
2009-09-16T07:30:00.000
11
1
0
0
python
1,431,524
3
false
0
0
Key code? If you send AT commands you are probably sending strings with ascii text and control codes, right? Ctrl-Z is usually 26 (decimal). So chr(26) should work, or if it's a part of a string, '\x1a' as 26 decimal is 1A hex. That said, Ctrl-Z is not usually a part of the AT command set... so if this doesn't help you, maybe you could explain more what you are trying to do and why you would need to send Ctrl-Z.
1
6
0
I want to send some modem AT commands using python code, and am wondering what is the keycode for the key combination control+z Gath
What is the keycode for control+z key in python?
1
0
0
13,499
1,432,480
2009-09-16T11:49:00.000
10
0
1
0
python,python-idle
1,435,237
22
false
0
0
There does not appear to be a way to clear the IDLE 'shell' buffer.
9
187
0
I know there's a similar topic about python console, but I do not know if they are the same. I tried system("clear") and it didn't work here. How do I clear python's IDLE window?
Any way to clear python's IDLE window?
1
0
0
585,254
1,432,480
2009-09-16T11:49:00.000
53
0
1
0
python,python-idle
24,466,596
22
false
0
0
Most of the answers, here do clearing the DOS prompt screen, with clearing commands, which is not the question. Other answers here, were printing blank lines to show a clearing effect of the screen. The simplest answer of this question is It is not possible to clear python IDLE shell without some external module integration. If you really want to get a blank pure fresh shell just close the previous shell and run it again
9
187
0
I know there's a similar topic about python console, but I do not know if they are the same. I tried system("clear") and it didn't work here. How do I clear python's IDLE window?
Any way to clear python's IDLE window?
1
0
0
585,254
1,432,480
2009-09-16T11:49:00.000
48
0
1
0
python,python-idle
29,189,588
22
false
0
0
ctrl + L clears the screen on Ubuntu Linux.
9
187
0
I know there's a similar topic about python console, but I do not know if they are the same. I tried system("clear") and it didn't work here. How do I clear python's IDLE window?
Any way to clear python's IDLE window?
1
0
0
585,254
1,432,480
2009-09-16T11:49:00.000
3
0
1
0
python,python-idle
42,591,664
22
false
0
0
It seems it is impossible to do it without any external library. An alternative way if you are using windows and don't want to open and close the shell everytime you want to clear it is by using windows command prompt. Type python and hit enter to turn windows command prompt to python idle (make sure python is installed). Type quit() and hit enter to turn it back to windows command prompt. Type cls and hit enter to clear the command prompt/ windows shell.
9
187
0
I know there's a similar topic about python console, but I do not know if they are the same. I tried system("clear") and it didn't work here. How do I clear python's IDLE window?
Any way to clear python's IDLE window?
0.027266
0
0
585,254
1,432,480
2009-09-16T11:49:00.000
2
0
1
0
python,python-idle
38,944,644
22
false
0
0
None of these solutions worked for me on Windows 7 and within IDLE. Wound up using PowerShell, running Python within it and exiting to call "cls" in PowerShell to clear the window. CONS: Assumes Python is already in the PATH variable. Also, this does clear your Python variables (though so does restarting the shell). PROS: Retains any window customization you've made (color, font-size).
9
187
0
I know there's a similar topic about python console, but I do not know if they are the same. I tried system("clear") and it didn't work here. How do I clear python's IDLE window?
Any way to clear python's IDLE window?
0.01818
0
0
585,254
1,432,480
2009-09-16T11:49:00.000
5
0
1
0
python,python-idle
51,869,884
22
false
0
0
"command + L" for MAC OS X. "control + L" for Ubuntu Clears the last line on the interactive session
9
187
0
I know there's a similar topic about python console, but I do not know if they are the same. I tried system("clear") and it didn't work here. How do I clear python's IDLE window?
Any way to clear python's IDLE window?
0.045423
0
0
585,254
1,432,480
2009-09-16T11:49:00.000
-3
0
1
0
python,python-idle
24,121,785
22
false
0
0
This works for me in Windows: print chr(12)
9
187
0
I know there's a similar topic about python console, but I do not know if they are the same. I tried system("clear") and it didn't work here. How do I clear python's IDLE window?
Any way to clear python's IDLE window?
-0.027266
0
0
585,254
1,432,480
2009-09-16T11:49:00.000
5
0
1
0
python,python-idle
4,550,807
22
false
0
0
File -> New Window In the new window** Run -> Python Shell The problem with this method is that it will clear all the things you defined, such as variables. Alternatively, you should just use command prompt. open up command prompt type "cd c:\python27" type "python example.py" , you have to edit this using IDLE when it's not in interactive mode. If you're in python shell, file -> new window. Note that the example.py needs to be in the same directory as C:\python27, or whatever directory you have python installed. Then from here, you just press the UP arrow key on your keyboard. You just edit example.py, use CTRL + S, then go back to command prompt, press the UP arrow key, hit enter. If the command prompt gets too crowded, just type "clr" The "clr" command only works with command prompt, it will not work with IDLE.
9
187
0
I know there's a similar topic about python console, but I do not know if they are the same. I tried system("clear") and it didn't work here. How do I clear python's IDLE window?
Any way to clear python's IDLE window?
0.045423
0
0
585,254
1,432,480
2009-09-16T11:49:00.000
5
0
1
0
python,python-idle
57,809,229
22
false
0
0
It seems like there is no direct way for clearing the IDLE console. One way I do it is use of exit() as the last command in my python script (.py). When I run the script, it always opens up a new console and prompt before exiting. Upside : Console is launched fresh each time the script is executed. Downside : Console is launched fresh each time the script is executed.
9
187
0
I know there's a similar topic about python console, but I do not know if they are the same. I tried system("clear") and it didn't work here. How do I clear python's IDLE window?
Any way to clear python's IDLE window?
0.045423
0
0
585,254
1,434,144
2009-09-16T16:42:00.000
0
0
1
0
python,compiler-construction
19,947,830
8
false
0
0
Answer for Windows first you must install python then set path variable after that write your python program and save think there is a python program that name "hello.py" open cmd.exe then goto the path that you saved your "hello.py" file, and then type python hello.py and press enter key. now the python code is automatically compile and show the result.
2
48
0
How can I compile and run a python file (*.py extension)?
Compiling Python
0
0
0
59,572
1,434,144
2009-09-16T16:42:00.000
8
0
1
0
python,compiler-construction
1,434,486
8
false
0
0
Python is an interpreted language, so you don't need to compile it; just to run it. As it happens, the standard version of python will compile this to "bytecode", just like Java etc. does, and will save that (in .pyc files) and run it next time around, saving time, if you haven't updated the file since. If you've updated the file, it will be recompiled automatically. You can also run python with a -O flag, which will generate .pyo files instead of .pyc. I'm not sure it makes much difference. If speed is important, use psyco. And yes, on Unix (including Linux, BSD, and Mac OS X, or in a unix shell on windows) you can use a shebang line at the top of the file to make the file automatically run using python. On windows, the equivalent is to associate .py files with python.exe, and then make sure your PATHEXT environment variable includes ".PY" extensions. However, for windows, you more likely want to write a gui program in python (possibly using PyQT4 and ERIC4) which has a .pyw file as its main script, and has .pyw associated with pythonw (which comes with python on windows). This will let you run python scripts on windows just like other GUI programs. For publishing and distribution, you probably want to compile to an executable file using something like py2exe, as others mentioned.
2
48
0
How can I compile and run a python file (*.py extension)?
Compiling Python
1
0
0
59,572
1,435,415
2009-09-16T20:56:00.000
2
0
1
0
python,debugging,memory-management,memory-leaks
9,352,959
9
false
0
0
This is by no means exhaustive advice. But number one thing to keep in mind when writing with the thought of avoiding future memory leaks (loops) is to make sure that anything which accepts a reference to a call-back, should store that call-back as a weak reference.
3
212
0
I have a long-running script which, if let to run long enough, will consume all the memory on my system. Without going into details about the script, I have two questions: Are there any "Best Practices" to follow, which will help prevent leaks from occurring? What techniques are there to debug memory leaks in Python?
Python memory leaks
0.044415
0
0
201,706
1,435,415
2009-09-16T20:56:00.000
3
0
1
0
python,debugging,memory-management,memory-leaks
1,435,434
9
false
0
0
Not sure about "Best Practices" for memory leaks in python, but python should clear it's own memory by it's garbage collector. So mainly I would start by checking for circular list of some short, since they won't be picked up by the garbage collector.
3
212
0
I have a long-running script which, if let to run long enough, will consume all the memory on my system. Without going into details about the script, I have two questions: Are there any "Best Practices" to follow, which will help prevent leaks from occurring? What techniques are there to debug memory leaks in Python?
Python memory leaks
0.066568
0
0
201,706
1,435,415
2009-09-16T20:56:00.000
13
0
1
0
python,debugging,memory-management,memory-leaks
1,435,485
9
false
0
0
You should specially have a look on your global or static data (long living data). When this data grows without restriction, you can also get troubles in Python. The garbage collector can only collect data, that is not referenced any more. But your static data can hookup data elements that should be freed. Another problem can be memory cycles, but at least in theory the Garbage collector should find and eliminate cycles -- at least as long as they are not hooked on some long living data. What kinds of long living data are specially troublesome? Have a good look on any lists and dictionaries -- they can grow without any limit. In dictionaries you might even don't see the trouble coming since when you access dicts, the number of keys in the dictionary might not be of big visibility to you ...
3
212
0
I have a long-running script which, if let to run long enough, will consume all the memory on my system. Without going into details about the script, I have two questions: Are there any "Best Practices" to follow, which will help prevent leaks from occurring? What techniques are there to debug memory leaks in Python?
Python memory leaks
1
0
0
201,706
1,436,384
2009-09-17T02:03:00.000
2
0
1
0
python,google-app-engine,loops
1,436,401
3
false
0
0
Classes are defined in modules. Modules are created by an import statement. Modules are simply dictionaries. If you want, you can use the dir(x) function on a module named x Or you can use x.__dict__ on a module named x.
1
2
0
How can I iterate over a list of all classes loaded in memory? I'm thinking of doing it for a backup, looking for all classes inheriting from db.Model (Google App Engine). Thanks, Neal Walters
Python - Iterate over all classes
0.132549
0
0
2,014
1,436,411
2009-09-17T02:18:00.000
2
0
1
0
python
1,436,482
6
false
0
0
10B booleans (1.25MB of memory, assuming Python is sane) I think you have your arithmetic wrong -- stored supercompactly, 10B booleans would be 1.25 GIGA, _not__ MEGA, bytes. A list takes at least 4 bytes per item, so you'd need 40GB to do it the way you want. You can store an array (see the array module in the standard library) in much less memory than that, so it might possibly fit.
2
2
1
I'm attempting to shorten the memory footprint of 10B sequential integers by referencing them as indexes in a boolean array. In other words, I need to create an array of 10,000,000,000 elements, but that's well into the "Long" range. When I try to reference an array index greater than sys.maxint the array blows up: x = [False] * 10000000000 Traceback (most recent call last): File "", line 1, in x = [0] * 10000000000 OverflowError: cannot fit 'long' into an index-sized integer Anything I can do? I can't seem to find anyone on the net having this problem... Presumably the answer is "python can't handle arrays bigger than 2B."
long-index arrays in python
0.066568
0
0
4,919
1,436,411
2009-09-17T02:18:00.000
3
0
1
0
python
1,436,547
6
false
0
0
A dense bit vector is plausible but it won't be optimal unless you know you won't have more than about 10**10 elements, all clustered near each other, with a reasonably randomized distribution. If you have a different distribution, then a different structure will be better. For instance, if you know that in that range, [0,10**10), only a few members are present, use a set(), or if the reverse is true, with nearly every element present except for a fraction, use a negated set, ie element not in mySet. If the elements tend to cluster around small ranges, you could use a run length encoding, something like [xrange(0,10),xrange(10,15),xrange(15,100)], which you lookup into by bisecting until you find a matching range, and if the index is even, then the element is in the set. inserts and removals involve shuffling the ranges a bit. If your distribution really is dense, but you need a little more than what fits in memory (seems to be typical in practice) then you can manage memory by using mmap and wrapping the mapped file with an adaptor that uses a similar mechanism to the suggested array('I') solution already suggested. To get an idea of just how compressible you can possibly get, try building a plain file with a reasonable corpus of data in packed form and then apply a general compression algorithm (such as gzip) to see how much reduction you see. If there is much reduction, then you can probably use some sort of space optimization in your code as well.
2
2
1
I'm attempting to shorten the memory footprint of 10B sequential integers by referencing them as indexes in a boolean array. In other words, I need to create an array of 10,000,000,000 elements, but that's well into the "Long" range. When I try to reference an array index greater than sys.maxint the array blows up: x = [False] * 10000000000 Traceback (most recent call last): File "", line 1, in x = [0] * 10000000000 OverflowError: cannot fit 'long' into an index-sized integer Anything I can do? I can't seem to find anyone on the net having this problem... Presumably the answer is "python can't handle arrays bigger than 2B."
long-index arrays in python
0.099668
0
0
4,919
1,436,962
2009-09-17T06:07:00.000
9
0
1
0
python,sorting
1,436,981
3
false
0
0
Well, the .sort() method of lists sorts the list in place, while sorted() creates a new list. So if you have a large list, part of your performance difference will be due to copying. Still, an order of magnitude difference seems larger than I'd expect. Perhaps list.sort() has some special-cased optimization that sorted() can't make use of. For example, since the list class already has an internal Py_Object*[] array of the right size, perhaps it can perform swaps more efficiently. Edit: Alex and Anurag are right, the order of magnitude difference is due to you accidentally sorting an already-sorted list in your test case. However, as Alex's benchmarks show, list.sort() is about 2% faster than sorted(), which would make sense due to the copying overhead.
1
40
1
I know that __builtin__ sorted() function works on any iterable. But can someone explain this huge (10x) performance difference between anylist.sort() vs sorted(anylist) ? Also, please point out if I am doing anything wrong with way this is measured. """ Example Output: $ python list_sort_timeit.py Using sort method: 20.0662879944 Using sorted builin method: 259.009809017 """ import random import timeit print 'Using sort method:', x = min(timeit.Timer("test_list1.sort()","import random;test_list1=random.sample(xrange(1000),1000)").repeat()) print x print 'Using sorted builin method:', x = min(timeit.Timer("sorted(test_list2)","import random;test_list2=random.sample(xrange(1000),1000)").repeat()) print x As the title says, I was interested in comparing list.sort() vs sorted(list). The above snippet showed something interesting that, python's sort function behaves very well for already sorted data. As pointed out by Anurag, in the first case, the sort method is working on already sorted data and while in second sorted it is working on fresh piece to do work again and again. So I wrote this one to test and yes, they are very close. """ Example Output: $ python list_sort_timeit.py Using sort method: 19.0166599751 Using sorted builin method: 23.203567028 """ import random import timeit print 'Using sort method:', x = min(timeit.Timer("test_list1.sort()","import random;test_list1=random.sample(xrange(1000),1000);test_list1.sort()").repeat()) print x print 'Using sorted builin method:', x = min(timeit.Timer("sorted(test_list2)","import random;test_list2=random.sample(xrange(1000),1000);test_list2.sort()").repeat()) print x Oh, I see Alex Martelli with a response, as I was typing this one.. ( I shall leave the edit, as it might be useful).
Python sort() method on list vs builtin sorted() function
1
0
0
63,711
1,437,357
2009-09-17T07:59:00.000
2
1
0
0
python,html,minimize
1,531,684
3
false
1
0
there are bindings to tidy for python, called mxTidy from eGenix (Marc André Lemburg)
1
1
0
I have a cherrypy web server that uses larges amounts of HTML data. Is there anyway in Python to minimize the HTML so that all comments, spaces, ext, are removed?
Python HTML Minimizer
0.132549
0
0
1,549
1,439,533
2009-09-17T15:19:00.000
0
1
0
0
python,exception,binding,exit
8,099,938
2
false
0
1
You can override the library linking with LD_LIBRARY_PATH and make your own exit function. Works fine.
2
7
0
I am embedding a c++ library (binding done with SIP) in my python application. Under certain circonstances (error cases), this library uses exit(), which causes my entire application to exit. Is there a way to catch this event, or do I need to modify the library to handle error cases differently ? Thank you very much,
How to catch exit() in embedded C++ module from python code?
0
0
0
1,407
1,439,533
2009-09-17T15:19:00.000
7
1
0
0
python,exception,binding,exit
1,439,585
2
true
0
1
You must modify the source of the library. There is no "exception handling" in C and exit() does not return to the calling code under any circumstances.
2
7
0
I am embedding a c++ library (binding done with SIP) in my python application. Under certain circonstances (error cases), this library uses exit(), which causes my entire application to exit. Is there a way to catch this event, or do I need to modify the library to handle error cases differently ? Thank you very much,
How to catch exit() in embedded C++ module from python code?
1.2
0
0
1,407
1,439,616
2009-09-17T15:33:00.000
0
0
0
0
python,mysql
1,439,734
1
true
0
0
Ha! Just realized I was trying to use the cursor after having closed the connection! In any case, it was nice writing! : ) l
1
0
0
I am just starting out with the MySQLdb module for python, and upon running some SELECT and UPDATE queries, the following gets output: Exception _mysql_exceptions.OperationalError: (2013, 'Lost connection to MySQL server during query') in bound method Cursor.del of MySQLdb.cursors.Cursor object at 0x8c0188c ignored The exception is apparently getting caught (and "ignored") by MySQLdb itself, so I guess this is not a major issue. Also, the SELECTs generate results and the table gets modified by UPDATE. But, since I am just getting my feet wet with this, I want to ask: does this message suggest I am doing something wrong? Or have you seen these warnings before in harmless situations? Thanks for any insight, lara
have you seen? _mysql_exceptions.OperationalError "Lost connection to MySQL server during query" being ignored
1.2
1
0
2,148
1,440,245
2009-09-17T17:34:00.000
6
0
0
0
python,psycopg2
1,492,172
2
true
0
0
psycopg2 doesn't pool connections unless you explicitely use the psycopg.pool module.
1
0
0
I have configured pgpool-II for postgres connection pooling and I want to disable psycopg2 connection pooling. How do I do this? Thanks!
How do I disable psycopg2 connection pooling?
1.2
1
0
1,426
1,440,434
2009-09-17T18:07:00.000
1
1
1
0
python,oop,class-design,procedural-programming
1,440,734
5
false
0
0
OOP lends itself well to complex programs. It's great for capturing the state and behavior of real world concepts and orchestrating the interplay between them. Good OO code is easy to read/understand, protects your data's integrity, and maximizes code reuse. I'd say code reuse is one big advantage to keeping your frequently used calculations in a class.
3
7
0
I write a lot of scripts in Python to analyze and plot experimental data as well as write simple simulations to test how theories fit the data. The scripts tend to be very procedural; calculate some property, calculate some other property, plot properties, analyze plot... Rather than just writing a procedure, would there be an benefits of using a Class? I can bury the actual analysis into functions so I can pass the data to the function and let it do it's thing but the functions are not contained in a Class. What sort of drawbacks would a Class over come and what would be the purpose of using a Class if it can be written procedurally? If this has been posted before my apologies, just point me in that direction.
Class usage in Python
0.039979
0
0
4,545
1,440,434
2009-09-17T18:07:00.000
1
1
1
0
python,oop,class-design,procedural-programming
1,447,527
5
false
0
0
Object-oriented programming isn't the solution to every coding problem. In Python, functions are objects. You can mix as many objects and functions as you want. Modules with functions are already objects with properties. If you find yourself passing a lot of the same variables around — state — an object is probably better suited. If you have a lot of classes with class methods, or methods that don't use self very much, then functions are probably better.
3
7
0
I write a lot of scripts in Python to analyze and plot experimental data as well as write simple simulations to test how theories fit the data. The scripts tend to be very procedural; calculate some property, calculate some other property, plot properties, analyze plot... Rather than just writing a procedure, would there be an benefits of using a Class? I can bury the actual analysis into functions so I can pass the data to the function and let it do it's thing but the functions are not contained in a Class. What sort of drawbacks would a Class over come and what would be the purpose of using a Class if it can be written procedurally? If this has been posted before my apologies, just point me in that direction.
Class usage in Python
0.039979
0
0
4,545
1,440,434
2009-09-17T18:07:00.000
4
1
1
0
python,oop,class-design,procedural-programming
1,440,655
5
false
0
0
You don't need to use classes in Python - it doesn't force you to do OOP. If you're more comfortable with the functional style, that's fine. I use classes when I want to model some abstraction which has variations, and I want to model those variations using classes. As the word "class" implies, they're useful mainly when the stuff you are working with falls naturally into various classes. When just manipulating large datasets, I've not found an overarching need to follow an OOP paradigm just for the sake of it.
3
7
0
I write a lot of scripts in Python to analyze and plot experimental data as well as write simple simulations to test how theories fit the data. The scripts tend to be very procedural; calculate some property, calculate some other property, plot properties, analyze plot... Rather than just writing a procedure, would there be an benefits of using a Class? I can bury the actual analysis into functions so I can pass the data to the function and let it do it's thing but the functions are not contained in a Class. What sort of drawbacks would a Class over come and what would be the purpose of using a Class if it can be written procedurally? If this has been posted before my apologies, just point me in that direction.
Class usage in Python
0.158649
0
0
4,545
1,440,941
2009-09-17T19:44:00.000
0
1
0
1
python,linux,process
1,440,965
7
false
0
0
The proc filesystem exports this (and other) information. Look at the /proc/PID/cmd symlink.
3
8
0
I'd like to know if it's possible to find out the "command" that a PID is set to. When I say command, I mean what you see in the last column when you run the command "top" in a linux shell. I'd like to get this information from Python somehow when I have a specific PID. Any help would be great. Thanks.
Finding the command for a specific PID in Linux from Python
0
0
0
9,565
1,440,941
2009-09-17T19:44:00.000
5
1
0
1
python,linux,process
1,443,544
7
false
0
0
Look in /proc/$PID/cmdline, and then os.readlink() on /proc/$PID/exe. /proc/$PID/cmdline is not necessarily going to be correct, as a program can change its argument vector or it may not contain a full path. Three examples of this from my current process list are: avahi-daemon: chroot helper qmgr -l -t fifo -u /usr/sbin/postgrey --pidfile=/var/run/postgrey.pid --daemonize --inet=127.0.0.1:60000 --delay=55 That first one is obvious - it's not a valid path or program name. The second is just an executable with no path name. The third looks ok, but that whole command line is actually in argv[0], with spaces separating the arguments. Normally you should have NUL separated arguments. All this goes to show that /proc/$PID/cmdline (or the ps(1) output) is not reliable. However, nor is /proc/$PID/exe. Usually it is a symlink to the executable that is the main text segment of the process. But sometimes it has " (deleted)" after it if the executable is no longer in the filesystem. Also, the program that is the text segment is not always what you want. For instance, /proc/$PID/exe from that /usr/sbin/postgrey example above is /usr/bin/perl. This will be the case for all interpretted scripts (#!). I settled on parsing /proc/$PID/cmdline - taking the first element of the vector, and then looking for spaces in that, and taking all before the first space. If that was an executable file - I stopped there. Otherwise I did a readlink(2) on /proc/$PID/exe and removed any " (deleted)" strings on the end. That first part will fail if the executable filename actually has spaces in it. There's not much you can do about that. BTW. The argument to use ps(1) instead of /proc/$PID/cmdline does not apply in this case, since you are going to fall back to /proc/$PID/exe. You will be dependent on the /proc filesystem, so you may as well read it with read(2) instead of pipe(2), fork(2), execve(2), readdir(3)..., write(2), read(2). While ps and /proc/$PID/cmdline may be the same from the point of view of lines of python code, there's a whole lot more going on behind the scenes with ps.
3
8
0
I'd like to know if it's possible to find out the "command" that a PID is set to. When I say command, I mean what you see in the last column when you run the command "top" in a linux shell. I'd like to get this information from Python somehow when I have a specific PID. Any help would be great. Thanks.
Finding the command for a specific PID in Linux from Python
0.141893
0
0
9,565
1,440,941
2009-09-17T19:44:00.000
6
1
0
1
python,linux,process
1,440,969
7
false
0
0
Look in /proc/$PID/cmdline
3
8
0
I'd like to know if it's possible to find out the "command" that a PID is set to. When I say command, I mean what you see in the last column when you run the command "top" in a linux shell. I'd like to get this information from Python somehow when I have a specific PID. Any help would be great. Thanks.
Finding the command for a specific PID in Linux from Python
1
0
0
9,565
1,441,502
2009-09-17T21:47:00.000
4
0
0
0
python,wxpython,wxtextctrl
1,442,312
1
true
0
1
How about setting the style wx.TE_NO_VSCROLL for the wx.TxtCtrl?
1
4
0
I have a wx.TextCtrl that I am using to represent a display with a fixed number of character rows and columns. I would like to hide the vertical scrollbar that is displayed to the right of the text pane since it is entirely unnecessary in my application. Is there a way to achieve this? Also...I would like to hide the blinking cursor that is displayed in the pane. Unfortunately, wx.TextCtrl.GetCaret() is returning None so I cannot call wx.Caret.Hide(). Environment info: Windows XP Python 2.5 wxPython 2.8
Hiding Vertical Scrollbar in wx.TextCtrl
1.2
0
0
2,839
1,441,967
2009-09-18T00:05:00.000
1
0
1
0
python,command-line,libraries,imaging
1,545,544
9
false
0
0
Take a look at some of these imaging libraries: hxxp://pypi.python.org/pypi/collective.croppingimagefield/0.1beta hxxp://pypi.python.org/pypi/cropresize/0.1.1 hxxp://pypi.python.org/pypi/image_resize/1.0
4
10
0
I have python code that needs to do just a couple simple things to photographs: crop, resize, and overlay a watermark. I've used PIL, and the resample/resize results are TERRIBLE. I've used imagemagick, and the interface and commands were designed by packaging a cat in a box, and then repeatedly throwing it down a set of stairs at a keyboard. I'm looking for something which is not PIL or Imagemagick that I can use with python to do simple, high-quality image transformations. For that matter, it doesn't even have to have python bindings if the command line interface is good. Oh, and it needs to be relatively platform agnostic, our production servers are linux, but some of our devs develop on windows. It can't require the installation of a bunch of silly gui code to use as a library, either.
Python imaging alternatives
0.022219
0
0
10,072
1,441,967
2009-09-18T00:05:00.000
18
0
1
0
python,command-line,libraries,imaging
1,442,062
9
true
0
0
I've used PIL, and the resample/resize results are TERRIBLE. They shouldn't be, as long as you: use only Image.ANTIALIAS filtering for downscaling operations use only Image.BICUBIC filtering for upscaling operations. remember to convert to 'RGB' colour mode before the resize if you are using a paletted image don't use .thumbnail(). it's crap set the quality= level to something appropriate when saving JPEGs (the default is quite low)
4
10
0
I have python code that needs to do just a couple simple things to photographs: crop, resize, and overlay a watermark. I've used PIL, and the resample/resize results are TERRIBLE. I've used imagemagick, and the interface and commands were designed by packaging a cat in a box, and then repeatedly throwing it down a set of stairs at a keyboard. I'm looking for something which is not PIL or Imagemagick that I can use with python to do simple, high-quality image transformations. For that matter, it doesn't even have to have python bindings if the command line interface is good. Oh, and it needs to be relatively platform agnostic, our production servers are linux, but some of our devs develop on windows. It can't require the installation of a bunch of silly gui code to use as a library, either.
Python imaging alternatives
1.2
0
0
10,072
1,441,967
2009-09-18T00:05:00.000
1
0
1
0
python,command-line,libraries,imaging
1,442,011
9
false
0
0
PIL can do good resizing. Make sure your source image is in RGB mode, not palette colors, and try the different algorithm choices.
4
10
0
I have python code that needs to do just a couple simple things to photographs: crop, resize, and overlay a watermark. I've used PIL, and the resample/resize results are TERRIBLE. I've used imagemagick, and the interface and commands were designed by packaging a cat in a box, and then repeatedly throwing it down a set of stairs at a keyboard. I'm looking for something which is not PIL or Imagemagick that I can use with python to do simple, high-quality image transformations. For that matter, it doesn't even have to have python bindings if the command line interface is good. Oh, and it needs to be relatively platform agnostic, our production servers are linux, but some of our devs develop on windows. It can't require the installation of a bunch of silly gui code to use as a library, either.
Python imaging alternatives
0.022219
0
0
10,072
1,441,967
2009-09-18T00:05:00.000
1
0
1
0
python,command-line,libraries,imaging
1,442,286
9
false
0
0
GIMP has a reasonable command-line interface, I think.
4
10
0
I have python code that needs to do just a couple simple things to photographs: crop, resize, and overlay a watermark. I've used PIL, and the resample/resize results are TERRIBLE. I've used imagemagick, and the interface and commands were designed by packaging a cat in a box, and then repeatedly throwing it down a set of stairs at a keyboard. I'm looking for something which is not PIL or Imagemagick that I can use with python to do simple, high-quality image transformations. For that matter, it doesn't even have to have python bindings if the command line interface is good. Oh, and it needs to be relatively platform agnostic, our production servers are linux, but some of our devs develop on windows. It can't require the installation of a bunch of silly gui code to use as a library, either.
Python imaging alternatives
0.022219
0
0
10,072
1,442,024
2009-09-18T00:22:00.000
3
0
1
1
python,path,executable
1,442,077
3
true
0
0
You can change the current directory of your script with os.chdir(). You can also set environment variables with os.environ
1
1
0
I'm trying to make a Python script run another program from its own path. I've got the execution of the other program working using os.system, but the program will crash because it cannot find its resources (wrong path, I assume). I tried adding the folder harboring the executable to the path, but that didn't help.
Python execute program change path
1.2
0
0
3,173
1,442,264
2009-09-18T02:00:00.000
4
0
1
0
python,c,datetime
1,442,541
6
false
0
0
I should be able to specify a timezone like "US/Eastern" and it should be smart enough to know whether a given timestamp should correspond to EST or EDT. This part isn't always possible - in the same way that 2:30am doesn't exist for one day of the year (in timezones with daylight saving that switches at 2:00am), 2:30am exists twice for another day - once in EDT and then an hour later in EST. If you pass that date/time to the library, how does it know which of the two times you're talking about?
1
7
0
I'm wondering if anyone knows of a good date and time library that has correctly-implemented features like the following: Microsecond resolution Daylight savings Example: it knows that 2:30am did not exist in the US on 8 March 2009 for timezones that respect daylight savings. I should be able to specify a timezone like "US/Eastern" and it should be smart enough to know whether a given timestamp should correspond to EST or EDT. Custom date ranges The ability to create specialized business calendars that skip over weekends and holidays. Custom time ranges The ability to define business hours so that times requested outside the business hours can be rounded up or down to the next or previous valid hour. Arithmetic Be able to add and subtract integer amounts of all units (years, months, weeks, days, hours, minutes, ...). Note that adding something like 0.5 days isn't well-defined because it could mean 12 hours or it could mean half the duration of a day (which isn't 24 hours on daylight savings changes). Natural boundary alignment Given a timestamp, I'd like be able to do things like round down to the nearest decade, year, month, week, ..., quarter hour, hour, etc. I'm currently using Python, though I'm happy to have a solution in another language like perl, C, or C++. I've found that the built-in Python libraries lack sophistication with their daylight savings logic and there isn't an obvious way (to me) to set up things like custom time ranges.
Full-featured date and time library
0.132549
0
0
5,826
1,443,173
2009-09-18T08:12:00.000
0
1
0
0
python,testing,mocking,module,monkeypatching
1,443,195
5
false
0
0
Yes, Python can do that, and so long as the methods exposed in the ResourceXSimulated module "look and smell" like these of the original module, the application should not see much any difference (other than, I'm assuming, bogus data fillers, different response times and such).
2
1
0
I want to simulate MyApp that imports a module (ResourceX) which requires a resource that is not available at the time and will not work. A solution for this is to make and import a mock module of ResourceX (named ResourceXSimulated) and divert it to MyApp as ResourceX. I want to do this in order to avoid breaking a lot of code and get all kinds of exception from MyApp. I am using Python and It should be something like: "Import ResourceXSimulated as ResourceX" "ResourceX.getData()", actually calls ResourceXSimultated.getData() Looking forward to find out if Python supports this kind of redirection. Cheers. ADDITIONAL INFO: I have access to the source files. UPDATE: I am thinking of adding as little code as possible to MyApp regarding using the fake module and add this code near the import statements.
Is it possible to divert a module in python? (ResourceX diverted to ResourceXSimulated)
0
0
1
256
1,443,173
2009-09-18T08:12:00.000
1
1
0
0
python,testing,mocking,module,monkeypatching
1,443,281
5
false
0
0
Yes, it's possible. Some starters: You can "divert" modules by manipulating sys.modules. It keeps a list of imported modules, and there you can make your module appear under the same name as the original one. You must do this manipulating before any module that imports the module you want to fake though. You can also make a package called a different name, but in that package actually use the original module name, for your completely different module. This works well as long as the original module isn't installed. In none of these cases you can use both modules at the same time. For that you need to monkey-patch the original module. And of course: It' perfectly possible to just call the new module with the old name. But it might be confusing.
2
1
0
I want to simulate MyApp that imports a module (ResourceX) which requires a resource that is not available at the time and will not work. A solution for this is to make and import a mock module of ResourceX (named ResourceXSimulated) and divert it to MyApp as ResourceX. I want to do this in order to avoid breaking a lot of code and get all kinds of exception from MyApp. I am using Python and It should be something like: "Import ResourceXSimulated as ResourceX" "ResourceX.getData()", actually calls ResourceXSimultated.getData() Looking forward to find out if Python supports this kind of redirection. Cheers. ADDITIONAL INFO: I have access to the source files. UPDATE: I am thinking of adding as little code as possible to MyApp regarding using the fake module and add this code near the import statements.
Is it possible to divert a module in python? (ResourceX diverted to ResourceXSimulated)
0.039979
0
1
256
1,444,651
2009-09-18T13:47:00.000
2
0
1
0
python,eclipse,pydev
1,445,869
1
false
0
0
When you hover your cursor over a function or class, Pydev should show you the docstring. Click on the function/class, then press F3, and it will take you to the definition of that function/class. If that is not happening, you probably have not configured Pydev correctly. Look over the documentation again, making sure you have done all the steps. If that still does not work, the Pydev author is very active and helpful on the pydev mailinglists. When you are debugging code, F5 will step into a function. F6 will step over.
1
2
0
I've been -trying- to use pydev to do some python (can't say I'm having good times so far). I finally got code completion working for the libraries I'm using, but I'm still wondering about a couple of things... So the library I'm using is called orange. Say I call the function orange.MakeRandomIndices2, but I'm not sure how it works... I want to see the source code of this function, or at least some useful information as to it's usage.. Is there any way to do this from my ide? Also while debugging, I might want to do just the same.. step into that function and debug it internally... I cannot seem to be able to do this and I just don't understand WHY seeing I have the source code on my hard disk. Thanks. JC
Pydev code browsing?
0.379949
0
0
894
1,444,961
2009-09-18T14:35:00.000
1
0
1
0
c++,python
2,930,737
13
false
0
0
The Clang project provides libraries for just parsing C++ code. Either with Clang and GCC you can generate an XML representation of the code If you prefer a more Pythonian solution you could also search for a C++ yacc grammar and use py-ply (Yacc for Python), but that seems the solution that needs more work
1
59
0
Google didn't turn up anything that seemed relevant. I have a bunch of existing, working C++ code, and I'd like to use python to crawl through it and figure out relationships between classes, etc. EDIT: Just wanted to point out: I don't think I need or want to parse every bit of C++; I just need something smart enough to pick up on class, function and member variable declarations, and to skip over function definitions.
Is there a good Python library that can parse C++?
0.015383
0
0
34,263
1,445,971
2009-09-18T17:48:00.000
1
0
0
0
python,django,idioms
1,446,128
2
false
1
0
Do you really want to use the db_column="complex" argument and call your field something else?
1
5
0
I have a model that needs to have a field named complex and another one named type. Those are both python reserved names. According to PEP 8, I should name them complex_ and type_ respectively, but django won't allow me to have fields named with a trailing underscore. Whats the proper way to handle this?
Whats the proper idiom for naming django model fields that are python reserved names?
0.099668
0
0
412
1,445,989
2009-09-18T17:52:00.000
3
0
0
0
javascript,python,django
1,446,136
8
false
1
0
You can include <script> tags inside your .html templates, and then build your data structures however is convenient for you. The template language isn't only for HTML, it can also do Javascript object literals. And Paul is right: it might be best to use a json module to create a JSON string, then insert that string into the template. That will handle the quoting issues best, and deal with deep structures with ease.
3
59
0
I'm using Django and Apache to serve webpages. My JavaScript code currently includes a data object with values to be displayed in various HTML widgets based on the user's selection from a menu of choices. I want to derive these data from a Python dictionary. I think I know how to embed the JavaScript code in the HTML, but how do I embed the data object in that script (on the fly) so the script's functions can use it? Put another way, I want to create a JavaScript object or array from a Python dictionary, then insert that object into the JavaScript code, and then insert that JavaScript code into the HTML. I suppose this structure (e.g., data embedded in variables in the JavaScript code) is suboptimal, but as a newbie I don't know the alternatives. I've seen write-ups of Django serialization functions, but these don't help me until I can get the data into my JavaScript code in the first place. I'm not (yet) using a JavaScript library like jQuery.
Passing Python Data to JavaScript via Django
0.07486
0
0
89,362
1,445,989
2009-09-18T17:52:00.000
2
0
0
0
javascript,python,django
1,446,060
8
false
1
0
It is suboptimal. Have you considered passing your data as JSON using django's built in serializer for that?
3
59
0
I'm using Django and Apache to serve webpages. My JavaScript code currently includes a data object with values to be displayed in various HTML widgets based on the user's selection from a menu of choices. I want to derive these data from a Python dictionary. I think I know how to embed the JavaScript code in the HTML, but how do I embed the data object in that script (on the fly) so the script's functions can use it? Put another way, I want to create a JavaScript object or array from a Python dictionary, then insert that object into the JavaScript code, and then insert that JavaScript code into the HTML. I suppose this structure (e.g., data embedded in variables in the JavaScript code) is suboptimal, but as a newbie I don't know the alternatives. I've seen write-ups of Django serialization functions, but these don't help me until I can get the data into my JavaScript code in the first place. I'm not (yet) using a JavaScript library like jQuery.
Passing Python Data to JavaScript via Django
0.049958
0
0
89,362
1,445,989
2009-09-18T17:52:00.000
1
0
0
0
javascript,python,django
1,448,178
8
false
1
0
Putting Java Script embedded into Django template is rather always bad idea. Rather, because there are some exceptions from this rule. Everything depends on the your Java Script code site and functionality. It is better to have seperately static files, like JS, but the problem is that every seperate file needs another connect/GET/request/response mechanism. Sometimes for small one, two liners code os JS to put this into template, bun then use django templatetags mechanism - you can use is in other templates ;) About objects - the same. If your site has AJAX construction/web2.0 like favour - you can achieve very good effect putting some count/math operation onto client side. If objects are small - embedded into template, if large - response them in another connection to avoid hangind page for user.
3
59
0
I'm using Django and Apache to serve webpages. My JavaScript code currently includes a data object with values to be displayed in various HTML widgets based on the user's selection from a menu of choices. I want to derive these data from a Python dictionary. I think I know how to embed the JavaScript code in the HTML, but how do I embed the data object in that script (on the fly) so the script's functions can use it? Put another way, I want to create a JavaScript object or array from a Python dictionary, then insert that object into the JavaScript code, and then insert that JavaScript code into the HTML. I suppose this structure (e.g., data embedded in variables in the JavaScript code) is suboptimal, but as a newbie I don't know the alternatives. I've seen write-ups of Django serialization functions, but these don't help me until I can get the data into my JavaScript code in the first place. I'm not (yet) using a JavaScript library like jQuery.
Passing Python Data to JavaScript via Django
0.024995
0
0
89,362
1,446,137
2009-09-18T18:20:00.000
4
0
1
0
python,cmd,command-line-interface
1,446,164
1
true
0
0
Yes, it would just be a case of making a number of commands that all reference the same function. This is common. It often helps to provide multiple common aliases for a command. It makes the user's life simpler because the odds of them guessing correctly are improved.
1
2
0
I am making a command line interface in Python 3.1.1 using the cmd module. Is there a way to create a command with more than one name e.g. "quit" and "exit"? Or would it just be a case of making a number of commands that all reference the same function?
Python cmd module command aliases
1.2
0
0
853
1,446,549
2009-09-18T19:58:00.000
8
1
0
0
python,text,binary,file-type
1,446,580
4
false
0
0
It's inherently not simple. There's no way of knowing for sure, although you can take a reasonably good guess in most cases. Things you might like to do: Look for known magic numbers in binary signatures Look for the Unicode byte-order-mark at the start of the file If the file is regularly 00 xx 00 xx 00 xx (for arbitrary xx) or vice versa, that's quite possibly UTF-16 Otherwise, look for 0s in the file; a file with a 0 in is unlikely to be a single-byte-encoding text file. But it's all heuristic - it's quite possible to have a file which is a valid text file and a valid image file, for example. It would probably be nonsense as a text file, but legitimate in some encoding or other...
1
17
0
I need identify which file is binary and which is a text in a directory. I tried use mimetypes but it isnt a good idea in my case because it cant identify all files mimes, and I have strangers ones here... I just need know, binary or text. Simple ? But I couldn´t find a solution... Thanks
How to identify binary and text files using Python?
1
0
0
20,864
1,446,672
2009-09-18T20:28:00.000
0
0
0
0
wxpython
1,483,678
1
false
0
1
If the main panel has the accelerator table with Alt+b, this should work. Maybe the sub-panels have their own accelerator tables that are conflicting? You might try inactivating these with subpanel.SetAcceleratorTable(wx.NullAcceleratorTable) for each subpanel.
1
2
0
Accelerators on wxPython do not seem to work with nested panels. In other words: ----------------------------------------------- | Main panel | | ----------------- ----------------- | | | Subpanel 1 | | Subpanel 2 | | | | accelerator | | accelerator | | | | key for 'a' | | key for 'b' | | | ----------------- ----------------- | ----------------------------------------------- When a control in subpanel 1 has focus, I want Alt+b to still trigger the control in subpanel 2 that uses b as its accelerator key. How do I do this? If it matters, I'm loading the panel with xrc into a plain old wx.Frame.
wxPython, nested panels and accelerators
0
0
0
336
1,447,422
2009-09-19T01:19:00.000
1
0
1
0
python
1,447,430
1
true
0
0
Python is pretty smart about knowing where it is run from. What happens if you just copy the whole directory tree to the thumb drive?
1
1
0
I have installed python from .msi installer in windows and installed a lot of other modules. i would like to have all these available on a portable thumbdrive, but i don't want to redownload all the extramodules. Is there a way i can convert my C:\python26* to a portable python installation?
Installed Python to portable python
1.2
0
0
450
1,447,575
2009-09-19T02:44:00.000
18
0
1
0
python,winapi,symlink,pywin32
20,511,634
10
false
0
0
os.symlink works on Python 3.3 using Windows 8.1 with an NTFS filesystem.
1
45
0
Does anyone know of a way to make/read symbolic links across versions of win32 from Python? Ideally there should be a minimum amount of platform specific code, as I need my app to be cross platform.
Symlinks on windows?
1
0
0
38,996
1,448,308
2009-09-19T10:42:00.000
4
0
0
0
python,google-app-engine,role-based
1,448,733
1
true
1
0
I would do this by adding a ListProperty for roles to the model representing users. The list contains any roles a given user belongs to. This way if you want to know whether a given user belongs to a given role (I expect, the most common operation), it is a fast membership test. You could put the role names directly into the lists as strings or add a layer of indirection to another entity specifying the details about the role so it is easy to change the details later. But, this has a runtime cost of an additional RPC to fetch the details about the role. The downside to this method comes if you want to remove all users from a given role, or perform any other kind of global operation. I suppose you could mark a role 'deleted', but then you still have data cluttering up all your user models until you clean them up manually. So I am curious to hear what others suggest.
1
5
0
I would like to ask what is the common way for handling role-based security with Google App Engine, Python? In the app.yaml, there is the "login" section, but available values are only "admin" and "required". How do you normally handle role-based security? Create the model with two tables: Roles and UserRoles Import values for Roles table Manually add User to UserRoles Check if user is in the right Roles group Any other idea or any other method for role-based security, please let us know!
Role-based security with Google App Engine and Python
1.2
0
0
2,588
1,448,582
2009-09-19T13:47:00.000
0
0
0
0
ironpython
1,448,617
2
false
0
0
Well i can\t quite get exactly what are you looking for, whole solution or maybe you've got problem with colors, if that second thing below you got some ideas The most simple solution would be to create 14-elements array with color that you write from hand with help of some graphic software and than simply fetch element with delta number while drawing You can also search some algorithm to draw gradient, but instead of drawing store its color to array, if you wil genrate 130 values then you can get your color like that mycolors[delta*10] Be more specific with your question, maybe then more people will abe bale to help you i hope that my answer in some way helps MTH
1
0
1
I am trying to plot some data in ipy. The data consists of three variables alpha,beta and delta. The alpha and beta values are the coordinates of the data points that I wish to plot using a hammer projection. I want to scale the colour of the markers according to the delta values, preferably in a rainbow scale colormap i.e. from red to blue. The delta values range from 0-13 and I want a linear colour correlation. Can anyone please help me, I am getting very frustrated. Many thanks Angela
Colour map in ipython
0
0
0
279
1,449,935
2009-09-20T00:33:00.000
3
0
1
0
python,svn,revision
1,450,760
11
false
0
0
I do this by simply running a small script when building my project. The script just calls svn info in combination with sed to get out the bare revision data and injects that number into the revision.txt file. The Hudson build server makes it even easier as it sets the SVN revision number as an environment variable right before invoking your Build scripts.
2
19
0
I have a python project under SVN, and I'm wanting to display the version number when it is run. Is there any way of doing this (such as automatically running a short script on commit which could update a version file, or querying an SVN repository in Python?)
Getting SVN revision number into a program automatically
0.054491
0
0
31,518
1,449,935
2009-09-20T00:33:00.000
1
0
1
0
python,svn,revision
1,458,623
11
false
0
0
I find the when it is run section slightly ambiguous - when it is run from where ? From an SVN checkout or from released code ? All the solutions work on injecting the SVN version somehow into the Python source or somewhere in the repository in a separate version file. The version file is changed on fresh checkouts, so clean checkouts need to be done before distribution. So my question of where the program is being run remains.
2
19
0
I have a python project under SVN, and I'm wanting to display the version number when it is run. Is there any way of doing this (such as automatically running a short script on commit which could update a version file, or querying an SVN repository in Python?)
Getting SVN revision number into a program automatically
0.01818
0
0
31,518
1,450,038
2009-09-20T01:33:00.000
0
1
0
0
python,queue
1,450,105
3
false
0
0
Are you considering single machine architecture, or a cluster of machines? Forwarding the image to an available worker process on the same machine or a different machine isn't profoundly different, particularly if you use TCP sockets. Knowing what workers are available, spawning more if necessary and the resources are available, having a fail-safe mechanism if a worker crashes, etc, gradually make the problem more complicated. It could be something as simple as using httplib to push the image to a private server running Apache or twisted and a collection of cgi applications. When you add another server, round robin the request amongst them.
1
2
0
I'm building a mobile photo sharing site in Python similar to TwitPic and have been exploring various queues to handle the image processing. I've looked into RabbitMQ and ActiveMQ but I'm thinking that there is a better solution for my use case. I'm looking for something a little more lightweight. I'm open to any suggestions.
Which queue is most appropriate?
0
0
0
290
1,450,180
2009-09-20T03:06:00.000
-5
0
0
0
python,tkinter
41,727,157
3
false
0
1
It is really simple in PyQt4 simply use this one single line below and you will be able to change focus by pressing tab button: self.textEdit.setTabChangesFocus(True)
1
15
0
I'm new to Python and I'm trying to create a simple GUI using Tkinter. So often in many user interfaces, hitting the tab button will change the focus from one Text widget to another. Whenever I'm in a Text widget, tab only indents the text cursor. Does anyone know if this is configurable?
Change the focus from one Text widget to another
-1
0
0
13,443
1,450,478
2009-09-20T06:59:00.000
10
0
1
1
python
1,451,204
6
false
0
0
It depends on what you mean by "a running python script". __file__ will give you the name of the currently executing file. If that's a module, you'll get where it was imported from e.g. blahblah.pyc sys.argv[0] will give you the name of the script that is being run, even if called from a module that that script imported. Please do look up the answers to the earlier question on this topic (see S.Lott's comment on your question).
2
12
0
How do I get the name of a running Python script? I tried os.__file__ but that returns the name of the file where os resides.
How to get the name of a running Python script?
1
0
0
16,150
1,450,478
2009-09-20T06:59:00.000
1
0
1
1
python
1,450,484
6
false
0
0
sys.argv[0] should give you the name of the script.
2
12
0
How do I get the name of a running Python script? I tried os.__file__ but that returns the name of the file where os resides.
How to get the name of a running Python script?
0.033321
0
0
16,150
1,450,897
2009-09-20T12:14:00.000
0
0
1
0
python,string
56,201,293
17
false
0
0
I used this. 'letters' should contain all the letters that you want to get rid of: Output = Input.translate({ord(i): None for i in 'letters'})) Example: Input = "I would like 20 dollars for that suit" Output = Input.translate({ord(i): None for i in 'abcdefghijklmnopqrstuvwxzy'})) print(Output) Output: 20
1
173
0
How can I remove all characters except numbers from string?
Remove characters except digits from string using Python?
0
0
0
259,411
1,451,138
2009-09-20T14:27:00.000
85
0
0
0
python,django,django-templates
1,451,155
18
true
1
0
I think what you want is to have access to the request context, see RequestContext.
2
202
0
How do I get the domain name of my current site from within a Django template? I've tried looking in the tag and filters but nothing there.
How can I get the domain name of my site within a Django template?
1.2
0
0
188,129
1,451,138
2009-09-20T14:27:00.000
-6
0
0
0
python,django,django-templates
23,763,770
18
false
1
0
You can use {{ protocol }}://{{ domain }} in your templates to get your domain name.
2
202
0
How do I get the domain name of my current site from within a Django template? I've tried looking in the tag and filters but nothing there.
How can I get the domain name of my site within a Django template?
-1
0
0
188,129
1,451,349
2009-09-20T16:01:00.000
2
0
0
0
python,sockets
1,451,356
2
true
0
0
There are two problems here. First problem, you will need to be able to address the remote party. This is related to what you referred to as "does not work over Internet as most ISP don't allow TCP server socket". It is usually difficult because the other party could be placed behind a NAT or a firewall. As for the second problem, the problem of actual transmitting of data after you can make a TCP connection, python socket would work if you can address the remote party.
2
1
0
I want to stream a binary data using python. I do not have any idea how to achieve it. I did created python socket program using SOCK_DGRAM. Problem with SOCK_STREAM is that it does not work over internet as our isp dont allow tcp server socket. I want to transmit screen shots periodically to remote computer. I have an idea of maintaining a Que of binary data and have two threads write and read synchronously. I do not want to use VNC . How do I do it? I did written server socket and client socket using SOCK_STREAM it was working on localhost and did not work over internet even if respective ip's are placed. We also did tried running tomcat web server on one pc and tried accessing via other pc on internet and was not working.
How to stream binary data in python
1.2
0
1
1,737
1,451,349
2009-09-20T16:01:00.000
3
0
0
0
python,sockets
1,451,365
2
false
0
0
SOCK_STREAM is the correct way to stream data. What you're saying about ISPs makes very little sense; they don't control whether or not your machine listens on a certain port on an interface. Perhaps you're talking about firewall/addressing issues? If you insist on using UDP (and you shouldn't because you'll have to worry about packets arriving out of place or not arriving at all) then you'll need to first use socket.bind and then socket.recvfrom in a loop to read data and keep track of open connections. It'll be hard work to do correctly.
2
1
0
I want to stream a binary data using python. I do not have any idea how to achieve it. I did created python socket program using SOCK_DGRAM. Problem with SOCK_STREAM is that it does not work over internet as our isp dont allow tcp server socket. I want to transmit screen shots periodically to remote computer. I have an idea of maintaining a Que of binary data and have two threads write and read synchronously. I do not want to use VNC . How do I do it? I did written server socket and client socket using SOCK_STREAM it was working on localhost and did not work over internet even if respective ip's are placed. We also did tried running tomcat web server on one pc and tried accessing via other pc on internet and was not working.
How to stream binary data in python
0.291313
0
1
1,737
1,452,148
2009-09-20T22:06:00.000
0
0
0
1
python,windows,windows-vista,pywin32
4,610,520
5
false
0
0
You could leverage the Tcl you have available with Tkinter, as that has a 'file link' command that knows about junctions, unlike Pythons os module.
1
4
0
Currently the buildout recipe collective.recipe.omelette uses junction.exe on all versions of Windows to create symlinks. However junction.exe does not come with Windows by default and most importantly does not support creating symlinks to files (only directories) which causes a problem with quite a few Python packages. On NT6+ (Vista and 7) there is now the mklink utility that not only comes by default but is also capable of creating symlinks to files as well as directories. I would like to update collective.recipe.omelette to use this if available and have done so except for one otherwise simple feature; detecting whether a file or folder is actually a symlink. Since this is a small buildout recipe, requiring Pywin32 in my opinion is a bit too much (unless setuptools could somehow only download it on Windows?). Currently on Windows what omelette does is call junction.exe on the folder and then grep the response for "Substitute Name:" but I can't find anything as simple for mklink. The only method I can think of is to call "dir" in the directory and then to go through the response line by line looking for "<SYMLINK>" and the folder/filename on the same line. Surely there is something better?
Detecting symlinks (mklink) on Vista/7 in Python without Pywin32
0
0
0
1,727
1,452,509
2009-09-21T01:24:00.000
1
1
1
0
python
1,452,566
9
false
0
0
Well, the short answer is, since you mentioned Perl, anything you could build in Perl you could build in Python. You can build anything in any language, and if the language has easy C bindings, you could even do it efficiently. Now, this being the case, the question becomes somewhat philosophical. Python has as a key tenet "There should only be one way to do it". Perl is exactly the opposite. The key tenet of Perl is "There Is More Than One Way To Do It" (TIMTOWTDI) or ( Tim Toady, to his frineds ;) ) How do you like to do things? One clear and shining path, agreed upon by most? Or perhaps you value the almost infinite number of solution paths that any task has in Perl? So, assuming that your task is I/O bound ( like most things ) rather than CPU bound ( real time programming or games , or nipple crinkling number crunching ) then Python would be suitable. Whether its philosophy suits you is the key question.
5
25
0
I wanted to know Python is suited for what kind of applications? I am new to Python world but I know it's a scripting language like Perl but I was not sure about the kind of applications which one would build using Python and would certainly appreciate if someone can provide some useful information.
What kind of applications are built using Python?
0.022219
0
0
80,717
1,452,509
2009-09-21T01:24:00.000
1
1
1
0
python
1,452,576
9
false
0
0
Most of the 3d packages these days, such as Maya, SoftImage, Houdini, RealFlow, Blender, etc. all use Python as an embedded scripting and plugin language.
5
25
0
I wanted to know Python is suited for what kind of applications? I am new to Python world but I know it's a scripting language like Perl but I was not sure about the kind of applications which one would build using Python and would certainly appreciate if someone can provide some useful information.
What kind of applications are built using Python?
0.022219
0
0
80,717
1,452,509
2009-09-21T01:24:00.000
10
1
1
0
python
1,452,546
9
false
0
0
You say: I am new to Python world but I know it's an scripting language. I think the distinction between "scripting languages" and "programming languages" is quite arbitrary. Nearly every language developed in the last 10-20 years has some kind of runtime support, usually in the form of a bytecode interpreter or virtual machine. Python is no different: it gets compiled to bytecode and the bytecode is executed by the Python runtime. The point is, I would say there are very few things you can do in Java, C#, Ruby, etc., that you couldn't do in Python. That said, however, different languages have different strengths. So there are certainly some kinds of programs that would be better suited to being written in Python. It really depends on what you want the programming language to do for you, and what you want to do yourself. The right answer depends on what kinds of problems you're interested in solving.
5
25
0
I wanted to know Python is suited for what kind of applications? I am new to Python world but I know it's a scripting language like Perl but I was not sure about the kind of applications which one would build using Python and would certainly appreciate if someone can provide some useful information.
What kind of applications are built using Python?
1
0
0
80,717
1,452,509
2009-09-21T01:24:00.000
33
1
1
0
python
1,452,532
9
true
0
0
It's hard to think of kinds of general applications where Python would be unsuitable, but there are several kinds where, like just about all higher-level languages akin to it, it might be considered a peculiar and probably inferior choice. In "hard real time" applications, all dynamic memory allocation and freeing, and especially garbage collection, are quite understandably frowned upon; this rules out almost all modern languages (including Python, but also Java, C#, etc, etc), since almost all of them rely on dynamic memory handling and garbage collection of some kind or other. If you're programming for an "embedded device" which you expect to be produced and sold in huge numbers, every bit of ROM may add measurably to the overall costs, so you want a language focused on squeezing the application down to the last possible bit -- any language that relies on a rich supporting runtime environment or operating system (including Python, and, again, also Java, C#, etc, etc) would no doubt force you to spend extra on many more bits of ROM (consider threaded-interpretive languages like good old Forth: they can make a substantial application's code be measurably more compact than straightforward machine code would!). There many be other niches that share similar constraints (mostly focused on MEMORY: focus on using as few bits as possible and/or strictly confining execution within precisely predefined limits -- no dynamism, no allocation, no garbage collection, etc, etc), and basically the case would once again incline in similar ways (for example, there are server applications, intended to run on myriads of servers, which can save many megabytes per server if coded in C++ [especially if without "allegedly-smart" pointers;-)] rather than Java, Python, C#, and so on). Of course there are excellent reasons most modern languages (Python, Java, C#, etc) choose to do dynamic memory allocation, garbage collection, and so forth, despite the importance of application niches where those techniques are a negative aspect: essentially, if you can possibly afford such nice memory handling, writing applications becomes MUCH, MUCH easier, and a whole class of problems and bugs connected with the need to carefully manage memory if you lack such support can go away -- programmer productivity really soars... IF garbage collection and the like can be afforded at all, that is. For example, if an application was going to run on a few hundreds or thousands of servers, I probably wouldn't bother coding it in C++ with manual memory management in order to save memory; it's only at tens and hundreds of thousands of servers, that the economics of all those extra megabytes really kicks in. Note that, despite the common misconception that "interpreted languages" (ones with a rich underlying runtime or VM, like Java, C#, Python, etc) "are slow", in fact for most CPU-intensive applications (such as scientific computation), Python is perfectly suitable, as long as the "rich supporting runtime environment" (e.g. numpy) is factored in. So, that is not really a factor -- though memory consumption and garbage collection CAN be, in some niches.
5
25
0
I wanted to know Python is suited for what kind of applications? I am new to Python world but I know it's a scripting language like Perl but I was not sure about the kind of applications which one would build using Python and would certainly appreciate if someone can provide some useful information.
What kind of applications are built using Python?
1.2
0
0
80,717
1,452,509
2009-09-21T01:24:00.000
0
1
1
0
python
1,452,528
9
false
0
0
Bittorrent was built on Python.
5
25
0
I wanted to know Python is suited for what kind of applications? I am new to Python world but I know it's a scripting language like Perl but I was not sure about the kind of applications which one would build using Python and would certainly appreciate if someone can provide some useful information.
What kind of applications are built using Python?
0
0
0
80,717
1,452,652
2009-09-21T02:44:00.000
4
0
0
0
java,php,python,ruby-on-rails
1,452,676
8
false
1
0
You've already tagged your question with "java", "php", "python", and "ruby-on-rails", so researching and learning more about those tools would probably help to answer your question. However, I believe that rapidly building an application is almost never actually the correct goal. Normally, what you want to do is build an application that can be rapidly maintained -- that is, maintained with the lowest possible overall development cost over time.
4
5
0
To build a Web Application, what kind of open source web application frameworks / technologies are currently present that would be: Faster to learn. Ease of use. Have widgets for rapid development(From a GUI perspective). Database integration. I would want this web app to communicate to a Java client. I am not bound to Java on the server side and free to try out any good rapid application framework. To summarize, I haven't done much work for the server side hence am not conversant with the tools and technologies for the same. What would you suggest? Any and every input would be welcome!...
How to rapidly build a Web Application?
0.099668
0
0
4,394
1,452,652
2009-09-21T02:44:00.000
1
0
0
0
java,php,python,ruby-on-rails
1,452,751
8
false
1
0
Speaking only in terms of speed of development, Ruby on Rails is the fastest one out there.
4
5
0
To build a Web Application, what kind of open source web application frameworks / technologies are currently present that would be: Faster to learn. Ease of use. Have widgets for rapid development(From a GUI perspective). Database integration. I would want this web app to communicate to a Java client. I am not bound to Java on the server side and free to try out any good rapid application framework. To summarize, I haven't done much work for the server side hence am not conversant with the tools and technologies for the same. What would you suggest? Any and every input would be welcome!...
How to rapidly build a Web Application?
0.024995
0
0
4,394
1,452,652
2009-09-21T02:44:00.000
2
0
0
0
java,php,python,ruby-on-rails
1,453,699
8
false
1
0
I would say part of the learning curve will go into understanding concepts. I have been learning about web-apps for some months now, and with my improved understanding of concepts right now, most frameworks show very much similarities. Here are my results so far: PHP: Great to learn about concepts for doing forms, http-post-requests, http-get-requests. easy interaction with database layer, and it is possible to obtain a working basic application in couple of hours. Almost no hassle with build-systems and web-server configuration. Ruby-on-Rails: Great to learn about REST and more complicated CRUD applications. Great to learn about the complexity behind MVC and especially simple and powerful interaction with the database layer by using ActiveRecord. Introduction of meta-programming (code-that-writes-code, code-scaffolding) is great. Nice opportunities for free cloud-deployment, e.g. heroku.com and there is a very active community Java: Powerful interaction with web-server possible (Tomcat, JBoss, ...) MVC is rather complicated here, and in general many configuration-steps necessary (build systems, ORM layer, ...) Grails is a great simplifaction and introduces meta-programming for Java. Jboss Seam introduces REST for Java (but have not looked into this yet)
4
5
0
To build a Web Application, what kind of open source web application frameworks / technologies are currently present that would be: Faster to learn. Ease of use. Have widgets for rapid development(From a GUI perspective). Database integration. I would want this web app to communicate to a Java client. I am not bound to Java on the server side and free to try out any good rapid application framework. To summarize, I haven't done much work for the server side hence am not conversant with the tools and technologies for the same. What would you suggest? Any and every input would be welcome!...
How to rapidly build a Web Application?
0.049958
0
0
4,394
1,452,652
2009-09-21T02:44:00.000
1
0
0
0
java,php,python,ruby-on-rails
1,452,667
8
false
1
0
There are tons, which ones are "good" depend on what you need. There's Ruby on Rails, which is pretty handy. For python there's django. For PHP (I spend a lot of time dealing with PHP), you can look at: symfony cakePHP Solar Zend Framework Which are all good in certain situations, and annoying in others.
4
5
0
To build a Web Application, what kind of open source web application frameworks / technologies are currently present that would be: Faster to learn. Ease of use. Have widgets for rapid development(From a GUI perspective). Database integration. I would want this web app to communicate to a Java client. I am not bound to Java on the server side and free to try out any good rapid application framework. To summarize, I haven't done much work for the server side hence am not conversant with the tools and technologies for the same. What would you suggest? Any and every input would be welcome!...
How to rapidly build a Web Application?
0.024995
0
0
4,394
1,452,694
2009-09-21T02:59:00.000
0
0
1
0
python,loops
1,452,705
5
false
0
0
What you want is two arrays and one loop, iterate over each array once, adding the results.
2
6
0
I want to create a loop who has this sense: for i in xrange(0,10): for k in xrange(0,10): z=k+i print z where the output should be 0 2 4 6 8 10 12 14 16 18
Creating Simultaneous Loops in Python
0
0
0
12,942
1,452,694
2009-09-21T02:59:00.000
2
0
1
0
python,loops
1,452,706
5
false
0
0
You can do this in python - just have to make the tabs right and use the xrange argument for step. for i in xrange(0, 20, 2); print i
2
6
0
I want to create a loop who has this sense: for i in xrange(0,10): for k in xrange(0,10): z=k+i print z where the output should be 0 2 4 6 8 10 12 14 16 18
Creating Simultaneous Loops in Python
0.07983
0
0
12,942
1,453,952
2009-09-21T10:52:00.000
2
0
1
0
python,module,standard-library
3,057,772
16
false
0
0
I think everyone here got all the important ones, except for sys. If you look at actual Python code, sys is probably one of the most commonly used modules (usually because of sys.version). Also, it's not really a module, but I would mention __future__. And nobody should use Python without doing import this.
11
55
0
I am teaching a graduate level Python class at the University of Paris, and the students need to be introduced to the standard library. I want to discuss with them about some of the most important standard modules. What modules do you think are absolute musts? Even though responses probably vary depending on your field (web programming, science, etc.), I feel that some modules are commonly needed: math, sys, re, os, os.path, logging,… and maybe: collections, struct,… What modules would you suggest I present, in a 1 or 2 hour slot?
Most useful Python modules from the standard library?
0.024995
0
0
24,060
1,453,952
2009-09-21T10:52:00.000
3
0
1
0
python,module,standard-library
1,456,618
16
false
0
0
os and os.path: because those are the core modules which anyone will require to write platform independent code in python and students can switch from shell script to python script after learning os and os.path.
11
55
0
I am teaching a graduate level Python class at the University of Paris, and the students need to be introduced to the standard library. I want to discuss with them about some of the most important standard modules. What modules do you think are absolute musts? Even though responses probably vary depending on your field (web programming, science, etc.), I feel that some modules are commonly needed: math, sys, re, os, os.path, logging,… and maybe: collections, struct,… What modules would you suggest I present, in a 1 or 2 hour slot?
Most useful Python modules from the standard library?
0.037482
0
0
24,060
1,453,952
2009-09-21T10:52:00.000
4
0
1
0
python,module,standard-library
1,454,636
16
false
0
0
operator, next to what's already mentioned.
11
55
0
I am teaching a graduate level Python class at the University of Paris, and the students need to be introduced to the standard library. I want to discuss with them about some of the most important standard modules. What modules do you think are absolute musts? Even though responses probably vary depending on your field (web programming, science, etc.), I feel that some modules are commonly needed: math, sys, re, os, os.path, logging,… and maybe: collections, struct,… What modules would you suggest I present, in a 1 or 2 hour slot?
Most useful Python modules from the standard library?
0.049958
0
0
24,060
1,453,952
2009-09-21T10:52:00.000
7
0
1
0
python,module,standard-library
5,252,164
16
false
0
0
I just remember a very practical module: copy. I use the deepcopy() from it quite often.
11
55
0
I am teaching a graduate level Python class at the University of Paris, and the students need to be introduced to the standard library. I want to discuss with them about some of the most important standard modules. What modules do you think are absolute musts? Even though responses probably vary depending on your field (web programming, science, etc.), I feel that some modules are commonly needed: math, sys, re, os, os.path, logging,… and maybe: collections, struct,… What modules would you suggest I present, in a 1 or 2 hour slot?
Most useful Python modules from the standard library?
1
0
0
24,060
1,453,952
2009-09-21T10:52:00.000
1
0
1
0
python,module,standard-library
1,454,028
16
false
0
0
Aside from those you mentioned, I found subprocess and sqlite3 modules particularly useful. But I would certainly advice to students to take a look at the list of standard library modules themselves. Also, from modules outside of standard library, I would mention numpy (or numarray) and pyparsing.
11
55
0
I am teaching a graduate level Python class at the University of Paris, and the students need to be introduced to the standard library. I want to discuss with them about some of the most important standard modules. What modules do you think are absolute musts? Even though responses probably vary depending on your field (web programming, science, etc.), I feel that some modules are commonly needed: math, sys, re, os, os.path, logging,… and maybe: collections, struct,… What modules would you suggest I present, in a 1 or 2 hour slot?
Most useful Python modules from the standard library?
0.012499
0
0
24,060
1,453,952
2009-09-21T10:52:00.000
3
0
1
0
python,module,standard-library
1,454,580
16
false
0
0
Don't forget about datetime, weakref, pickle, StringIO, heapq, may be threading. And numpy also worths mentioning, although it is not from the standard library.
11
55
0
I am teaching a graduate level Python class at the University of Paris, and the students need to be introduced to the standard library. I want to discuss with them about some of the most important standard modules. What modules do you think are absolute musts? Even though responses probably vary depending on your field (web programming, science, etc.), I feel that some modules are commonly needed: math, sys, re, os, os.path, logging,… and maybe: collections, struct,… What modules would you suggest I present, in a 1 or 2 hour slot?
Most useful Python modules from the standard library?
0.037482
0
0
24,060
1,453,952
2009-09-21T10:52:00.000
41
0
1
0
python,module,standard-library
1,454,779
16
true
0
0
Modules to cover in a 1-2 hour slot entirely depend on your audience's interest or focus. What other classes are they taking? What are they prepared to make use of immediately? Be sure to mention math, decimal and datetime and time and re. For IT-types who will be doing file-oriented work: glob, fnmatch, os, os.path, tempfile, and shutil. Database folks must hear about sqlite and json. Simulation audience may want to hear about random. Web developers must hear about urllib2 from a client point of view. Also Beautiful Soup and an XML parser of your choice. Web developers must hear about logging and wsgiref from a server point of view.
11
55
0
I am teaching a graduate level Python class at the University of Paris, and the students need to be introduced to the standard library. I want to discuss with them about some of the most important standard modules. What modules do you think are absolute musts? Even though responses probably vary depending on your field (web programming, science, etc.), I feel that some modules are commonly needed: math, sys, re, os, os.path, logging,… and maybe: collections, struct,… What modules would you suggest I present, in a 1 or 2 hour slot?
Most useful Python modules from the standard library?
1.2
0
0
24,060
1,453,952
2009-09-21T10:52:00.000
6
0
1
0
python,module,standard-library
1,454,863
16
false
0
0
It depends a little on what they will be doing and what level they are. Some modules I wish someone pointed out to me when I started are: StringIO - to stop them from reimplementing it, which they will if they don't discover it. logging - to put them on the right path when it comes to debug printouts pickle - to stop them from trying to use XML everywhere. xml.etree.ElementTree - To save them from the DOM model when they actually need to work with XML. pprint - to make nested structures in python less intimidating.
11
55
0
I am teaching a graduate level Python class at the University of Paris, and the students need to be introduced to the standard library. I want to discuss with them about some of the most important standard modules. What modules do you think are absolute musts? Even though responses probably vary depending on your field (web programming, science, etc.), I feel that some modules are commonly needed: math, sys, re, os, os.path, logging,… and maybe: collections, struct,… What modules would you suggest I present, in a 1 or 2 hour slot?
Most useful Python modules from the standard library?
1
0
0
24,060