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
3,916,553
2010-10-12T15:50:00.000
-5
1
0
0
python,garbage-collection,root,performance
3,919,321
3
false
0
1
If your problem really is the garbage collection, try explicitly freeing your objects when you're done with them using del(). In general, this doesn't sound like a garbage collection problem, unless we're talking about terabytes of memory. I agree with S.Lott... profile your app, then bring code snippets and the results of that back and we can be much more helpful.
1
18
0
I have a problem with my python application, and I think it's related to the python garbage collection, even if I'm not sure... The problem is that my application takes a lot of time to exit and to switch to one function to the next one. In my application I handle very large dictionaries, containing thousands of large objects which are instantiated from wrapped C++ classes. I put some timestamp outputs in my program, and I saw that at the end of each function, when objects created inside the function should go out of scope, a lot of time is spent by the interpreter before calling the next function. And I observe the same problem at the end of the application, when the program should exit: a lot of time (~ hours!) is spent between the last timestamp on screen and the appearance of the fresh prompt. The memory usage is stable, so I don't really have memory leaks. Any suggestions? Can be the garbage collection of thousands of large C++ objects that slow? Is there a method to speed up that? UPDATE: Thanks a lot for all your answers, you gave me a lot of hints to debug my code :-) I use Python 2.6.5 on Scientific Linux 5, a customized distribution based on Red Hat Enterprise 5. And actually I'm not using SWIG to get Python bindings for our C++ code, but the Reflex/PyROOT framework. I know, it's not very known outside particle physics (but still open source and freely available) and I have to use it because it's the default for our main framework. And in this context the DEL command from the Python side does not work, I had already tried it. DEL only deletes the python variable linked to the C++ object, not the object itself in memory, which is still owned by the C++ side... ...I know, it's not-standard I guess, and a bit complicated, sorry :-P But following your hints, I'll profile my code and I'll come back to you with more details, as you suggested. ADDITIONAL UPDATE: Ok, following your suggestions, I instrumented my code with cProfile, and I discovered that actually the gc.collect() function is the function taking the most of the running time!! Here the output from cProfile + pstats print_stats(): >>> p.sort_stats("time").print_stats(20) Wed Oct 20 17:46:02 2010 mainProgram.profile 547303 function calls (542629 primitive calls) in 548.060 CPU seconds Ordered by: internal time List reduced from 727 to 20 due to restriction ncalls tottime percall cumtime percall filename:lineno(function) 4 345.701 86.425 345.704 86.426 {gc.collect} 1 167.115 167.115 200.946 200.946 PlotD3PD_v3.2.py:2041(PlotSamplesBranches) 28 12.817 0.458 13.345 0.477 PlotROOTUtils.py:205(SaveItems) 9900 10.425 0.001 10.426 0.001 PlotD3PD_v3.2.py:1973(HistoStyle) 6622 5.188 0.001 5.278 0.001 PlotROOTUtils.py:403(__init__) 57 0.625 0.011 0.625 0.011 {built-in method load} 103 0.625 0.006 0.792 0.008 dbutils.py:41(DeadlockWrap) 14 0.475 0.034 0.475 0.034 {method 'dump' of 'cPickle.Pickler' objects} 6622 0.453 0.000 5.908 0.001 PlotROOTUtils.py:421(CreateCanvas) 26455 0.434 0.000 0.508 0.000 /opt/root/lib/ROOT.py:215(__getattr__) [...] >>> p.sort_stats("cumulative").print_stats(20) Wed Oct 20 17:46:02 2010 mainProgram.profile 547303 function calls (542629 primitive calls) in 548.060 CPU seconds Ordered by: cumulative time List reduced from 727 to 20 due to restriction ncalls tottime percall cumtime percall filename:lineno(function) 1 0.001 0.001 548.068 548.068 PlotD3PD_v3.2.py:2492(main) 4 0.000 0.000 346.756 86.689 /usr/lib//lib/python2.5/site-packages/guppy/heapy/Use.py:171(heap) 4 0.005 0.001 346.752 86.688 /usr/lib//lib/python2.5/site-packages/guppy/heapy/View.py:344(heap) 1 0.002 0.002 346.147 346.147 PlotD3PD_v3.2.py:2537(LogAndFinalize) 4 345.701 86.425 345.704 86.426 {gc.collect} 1 167.115 167.115 200.946 200.946 PlotD3PD_v3.2.py:2041(PlotBranches) 28 12.817 0.458 13.345 0.477 PlotROOTUtils.py:205(SaveItems) 9900 10.425 0.001 10.426 0.001 PlotD3PD_v3.2.py:1973(HistoStyle) 13202 0.336 0.000 6.818 0.001 PlotROOTUtils.py:431(PlottingCanvases) 6622 0.453 0.000 5.908 0.001 /root/svn_co/rbianchi/SoftwareDevelopment [...] >>> So, in both outputs, sorted by "time" and by "cumulative" time respectively, gc.collect() is the function consuming the most of the running time of my program! :-P And this is the output of the memory profiler Heapy, just before returning the main() program. memory usage before return: Partition of a set of 65901 objects. Total size = 4765572 bytes. Index Count % Size % Cumulative % Kind (class / dict of class) 0 25437 39 1452444 30 1452444 30 str 1 6622 10 900592 19 2353036 49 dict of PlotROOTUtils.Canvas 2 109 0 567016 12 2920052 61 dict of module 3 7312 11 280644 6 3200696 67 tuple 4 6622 10 238392 5 3439088 72 0xa4ab74c 5 6622 10 185416 4 3624504 76 PlotROOTUtils.Canvas 6 2024 3 137632 3 3762136 79 types.CodeType 7 263 0 129080 3 3891216 82 dict (no owner) 8 254 0 119024 2 4010240 84 dict of type 9 254 0 109728 2 4119968 86 type Index Count % Size % Cumulative % Kind (class / dict of class) 10 1917 3 107352 2 4264012 88 function 11 3647 5 102116 2 4366128 90 ROOT.MethodProxy 12 148 0 80800 2 4446928 92 dict of class 13 1109 2 39924 1 4486852 93 __builtin__.wrapper_descriptor 14 239 0 23136 0 4509988 93 list 15 87 0 22968 0 4532956 94 dict of guppy.etc.Glue.Interface 16 644 1 20608 0 4553564 94 types.BuiltinFunctionType 17 495 1 19800 0 4573364 94 __builtin__.weakref 18 23 0 11960 0 4585324 95 dict of guppy.etc.Glue.Share 19 367 1 11744 0 4597068 95 __builtin__.method_descriptor Any idea why, or how to optimize the garbage collection? Is there any more detailed check I can do?
Python garbage collection can be that slow?
-1
0
0
13,216
3,916,787
2010-10-12T16:15:00.000
1
0
1
0
python,ironpython,razor
3,916,880
3
false
0
0
I was at a talk by one of the guys working on IronPython and IronRuby. The general sentiment he seemed to express is that IronPython is not as up to the task of building modern ASP.NET MVC sites as IronRuby or C# are. That said, this could have changed since then. But you're comparing apples to oranges here. IronPython is a full-fledged dynamic language. Razor is just a markup language and view engine for defining views in an ASP.NET MVC site. The controllers and most of the code for the application must still be written in an actual language (such as C#, Python, or the like).
3
2
0
I have a little bit of experience with the new Razor syntax, but none with Iron Python. I was wondering do both meet the same needs? Is one favored by Microsoft over the other (or will be)? Appreciate your thoughts, as I'm toying with the idea of learning Iron Python, but if Razor can meet the same need, I probably won't.
Iron Python vs Razor
0.066568
0
0
1,405
3,916,787
2010-10-12T16:15:00.000
5
0
1
0
python,ironpython,razor
3,916,814
3
false
0
0
Razor is a view engine for ASP.NET MVC 3 - so i believe it has nothing to do with the space that IronPython occupies if im wrong then i have certainly missed something
3
2
0
I have a little bit of experience with the new Razor syntax, but none with Iron Python. I was wondering do both meet the same needs? Is one favored by Microsoft over the other (or will be)? Appreciate your thoughts, as I'm toying with the idea of learning Iron Python, but if Razor can meet the same need, I probably won't.
Iron Python vs Razor
0.321513
0
0
1,405
3,916,787
2010-10-12T16:15:00.000
7
0
1
0
python,ironpython,razor
3,917,668
3
true
0
0
To expand on the answer given by PaulStack: Razor is a templating engine (with a slant towards templating XML-style documents, e.g. HTML web pages) that is available as a View Engine in MVC 3 as well as the default page syntax in ASP.NET Web Pages (which is part of the WebMatrix stack). The Razor parser uses assumptions about the structure of XML documents as well as constructs available in the two supported programming languages (C# and Visual Basic) to minimize the number of transition characters that are required to go between code mode and markup mode. While it has been written with a focus on emitting HTML, it has been generalized to support arbitrary text templating tasks (though in some cases you might need to use special transition tokens to force switches between code and text). On the other hand, IronPython is a programming language. It is not a templating engine, though naturally it can be used to write code that emits a stream of text. If you are already comfortable with C# (or VB) then I would suggest you try Razor. It's a fairly simple extension of the language syntax and allows for very smooth transitions between markup and code.
3
2
0
I have a little bit of experience with the new Razor syntax, but none with Iron Python. I was wondering do both meet the same needs? Is one favored by Microsoft over the other (or will be)? Appreciate your thoughts, as I'm toying with the idea of learning Iron Python, but if Razor can meet the same need, I probably won't.
Iron Python vs Razor
1.2
0
0
1,405
3,917,574
2010-10-12T17:56:00.000
-2
0
1
0
python,arrays,list,linked-list,python-internals
60,759,244
9
false
0
0
In CPython list is implemented as dynamic array, and therefore when we append at that time not only one macro is added but some more space is allocated so that everytime new space should not be added.
3
249
0
Is it a linked list, an array? I searched around and only found people guessing. My C knowledge isn't good enough to look at the source code.
How is Python's List Implemented?
-0.044415
0
0
121,568
3,917,574
2010-10-12T17:56:00.000
5
0
1
0
python,arrays,list,linked-list,python-internals
19,508,262
9
false
0
0
As others have stated above, the lists (when appreciably large) are implemented by allocating a fixed amount of space, and, if that space should fill, allocating a larger amount of space and copying over the elements. To understand why the method is O(1) amortized, without loss of generality, assume we have inserted a = 2^n elements, and we now have to double our table to 2^(n+1) size. That means we're currently doing 2^(n+1) operations. Last copy, we did 2^n operations. Before that we did 2^(n-1)... all the way down to 8,4,2,1. Now, if we add these up, we get 1 + 2 + 4 + 8 + ... + 2^(n+1) = 2^(n+2) - 1 < 4*2^n = O(2^n) = O(a) total insertions (i.e. O(1) amortized time). Also, it should be noted that if the table allows deletions the table shrinking has to be done at a different factor (e.g 3x)
3
249
0
Is it a linked list, an array? I searched around and only found people guessing. My C knowledge isn't good enough to look at the source code.
How is Python's List Implemented?
0.110656
0
0
121,568
3,917,574
2010-10-12T17:56:00.000
40
0
1
0
python,arrays,list,linked-list,python-internals
3,917,596
9
false
0
0
In CPython, lists are arrays of pointers. Other implementations of Python may choose to store them in different ways.
3
249
0
Is it a linked list, an array? I searched around and only found people guessing. My C knowledge isn't good enough to look at the source code.
How is Python's List Implemented?
1
0
0
121,568
3,919,922
2010-10-13T00:00:00.000
1
0
1
0
python,parsing
3,920,000
3
false
0
0
Regular expressions are not the way to go here. The languages already have a defined grammar, so use that.
1
5
0
Given a code base (say for example a large C or Objective-C project) I would like to analyze the sourcecode files and pick out symbols of interest. They might be class declarations, variable names or types, or method names. Is there a Python module that could help me with this? The only approach I can see going forward is to use regular expressions to gather these symbols, but I'm thinking this could get very ugly very quickly. I'm also not an expert in compilers or parsers, so something lighter-weight would be prefereable. thanks for any suggestions. ------ update ----- thanks for all of the suggestions so far, definitely some promising leads. One other avenue that may be possible: what if I were able to compile the project I was trying to analyze. Would the debugging symbols (dsym) make this process any easier? I'm not looking for anything advanced, just a list of classes, with their ivar and method names. At this point, looking into the parsing tools suggested seem like more work than I can afford to invest in this project right now
Picking out symbols from a code base with Python
0.066568
0
0
151
3,920,842
2010-10-13T04:47:00.000
1
0
0
0
python,crash,wsgi,restart
3,923,177
2
true
1
0
I'd use your operational system's service integration to do that. For example, on debian linux, there's start-stop-daemon. On windows, there's the service management. It's the proven, well integrated way, provided by the operational system itself, to keep an application running. Just make your installation program register your service with the native service management system.
1
0
0
i have a wsgi server which use paste,for some unkonw reason,it will often crash,so i want to has a application or just some package can help me to slove this,when it crashed automaticly kill the process and restart it.Any advice is welcome.
how to monitor python wsgi server,when it crashed restart it
1.2
0
0
829
3,920,873
2010-10-13T04:55:00.000
1
0
1
0
python,twos-complement
3,931,412
3
false
0
0
if you want to do it without converting back to a number, start from the right of the string until you find the first 1, then flip all chars to its left.
1
1
0
I am trying to add the Two's Complement to a Binary number represented with a string. Assuming the string has already been flipped, how would I go about "adding" 1 to the last character, and replacing the other characters in the string as needed? Example: 100010 is flipped to 011101, and is represented as a string. How would you apply the Two's Complement to the 011101 string? One part of this that really has me puzzled is if the user enters a binary number that, when the two's complement is applied, involves a lot of carrying.
Python - Applying Two's Complement to a String
0.066568
0
0
3,323
3,922,135
2010-10-13T09:02:00.000
2
0
0
1
python,process,pyqt4,pid
3,922,943
3
false
0
0
While it's not related to the way of the communication, I recommend checking out the pickle/cPickle module (which can encode objects into string streams and vice versa). Very useful.
2
12
0
I have two python applications. I need to send commands and data between them (between two processes). What is the best way to do that? One program is a daemon who should accept commands and parameters from another GUI application. How can I make daemon to monitor comands from GUI, while making it's job? I prefer solution would be crossplatform. p.s. I use pyqt4 and python.
How to interchange data between two python applications?
0.132549
0
0
6,055
3,922,135
2010-10-13T09:02:00.000
10
0
0
1
python,process,pyqt4,pid
3,922,174
3
true
0
0
You can use the following methods for data interchange: Socket Programming : In Qt you can access QtNetwork module. See qt assistant for examples IPC : Use shared Memory implemented in QSharedMemory class. If this application will run on unix os only, then you can try Posix based message queue etc. for data interchange DBUS : You will find both python and Qt have DBus based support. In Case of python you need to find the relevant module. Using Multi Processing module Using Posix/SystemV based IPC mechanism aka pipes, queue, etc.
2
12
0
I have two python applications. I need to send commands and data between them (between two processes). What is the best way to do that? One program is a daemon who should accept commands and parameters from another GUI application. How can I make daemon to monitor comands from GUI, while making it's job? I prefer solution would be crossplatform. p.s. I use pyqt4 and python.
How to interchange data between two python applications?
1.2
0
0
6,055
3,924,668
2010-10-13T14:19:00.000
1
0
0
0
python,web-applications,webserver,nginx
3,965,912
3
true
1
0
Available options are: apache + mod_python apache + mod_wsgi lighttpd + mod_fastcgi lighttpd + gunicorn nginx + gunicorn I suggest you to go for gunicorn.
1
2
0
I've made a small web app using web.py that I now want to put into production. I dont anticipate this will have very high concurrent use (probably max of 5 or so users at any given time, if that). That said, I dont want to go with the cherry.py server that comes with web.py (and which i have been using for debugging), because one of my main motivations for the app was to learn how to properly put apps in production. Reading up on options - there seems to be dizzying array of stuff. Tornoado, nginx, lighttpd etc etc. Also stuff like Gunicorn, which I cant quite grasp the use of so far. It seems WSGI is the way to go - and I wanted some help with what would be an appropriate, relatively easy to administer setup that i can run on an EC2 instance (ubuntu), perhaps using nginx/wsgi. Specifically, do i need gunicorn (or equivalent), and are there any good intros anybody may know of so i can actually get my web.py code running and at least start to understand this jigsaw of various technologies/options? Many thanks
Python webapp - moving from testing to production
1.2
0
0
444
3,926,712
2010-10-13T18:19:00.000
1
0
0
1
python,google-app-engine
3,926,731
2
false
0
0
You can just open them (only read only).
2
1
0
Is there a way to read the contents of a static data directory or interact with that data in any way from within the code of an application? Edit: Please excuse me if it wasn't clear at first, I mean getting a list of the files in that directory, not reading the data in them.
Read static content from within the code of an application
0.099668
0
0
97
3,926,712
2010-10-13T18:19:00.000
3
0
0
1
python,google-app-engine
3,927,648
2
true
0
0
No. Files marked as static in app.yaml are not available to your application; they're served from separate servers. If you just need to list them, you could build a list as part of your deploy process. If you need to actually read them, you'll need to include a second copy in your application directory (although the "copy" can be just a symlink; appcfg.py will follow symlinks and upload them.)
2
1
0
Is there a way to read the contents of a static data directory or interact with that data in any way from within the code of an application? Edit: Please excuse me if it wasn't clear at first, I mean getting a list of the files in that directory, not reading the data in them.
Read static content from within the code of an application
1.2
0
0
97
3,927,166
2010-10-13T19:13:00.000
8
0
1
0
python,arrays,variables
3,927,214
6
false
0
0
Hmmm, seems weird, but possible. Sounds like you need a class which records the time when __init__ is called. Then, implement __getitem__ to check the time when it is called, and only return the item if it's not too late. (It's probably easier to do this than to have a process "running in the background" which actively deletes items even when you don't ask for them.)
2
8
0
How to implement an automatically expiring variable in python? For example, Let the program running For one hour. I want implement an array of 6 variables, each variable in array will be automatically deleted themselves after 10 mins. And after 1 hour, there will be no variable in the array.
Automatically expiring variable
1
0
0
5,819
3,927,166
2010-10-13T19:13:00.000
1
0
1
0
python,arrays,variables
3,927,215
6
false
0
0
It sounds like the items in your array know about each other, because otherwise they'll all expire at the same time. I think you want to create a subclass of list which deletes its contents after a certain time.
2
8
0
How to implement an automatically expiring variable in python? For example, Let the program running For one hour. I want implement an array of 6 variables, each variable in array will be automatically deleted themselves after 10 mins. And after 1 hour, there will be no variable in the array.
Automatically expiring variable
0.033321
0
0
5,819
3,928,685
2010-10-13T22:48:00.000
2
0
0
0
python,symbian,pys60
4,002,429
1
true
0
0
Symbian C++ API has such a capability, so it is possible to write a python library for that, but if such already exists, that I do not know... BR STeN
1
0
0
Is there any way in python for S60 (using the python 2.5.4 codebase) to track the amount of data transferred over the mobile device's internet connection?
Measuring internet data transfers
1.2
0
1
83
3,929,005
2010-10-13T23:58:00.000
0
0
0
0
python,screen-scraping
3,992,151
4
false
1
0
For nonprogrammers, I recomment using IRobotSoft. It is visual oriented and with full javascript support. The shortcoming is that it runs only on Windows. The good thing is you can become an expert just by trial and error to learn the software.
1
2
0
Disclaimer here: I'm really not a programmer. I'm eager to learn, but my experience is pretty much basic on c64 20 years ago and a couple of days of learning Python. I'm just starting out on a fairly large (for me as a beginner) screen scraping project. So far I have been using python with mechanize+lxml for my browsing/parsing. Now I'm encountering some really javascript heavy pages that doesn't show a anything without javascript enabled, which means trouble for mechanize. From my searching I've kind come to the conclusion that I have a basically a few options: Trying to figure out what the javascript is doing a emulate that in my code (I don't quite know where to start with this. ;-)) Using pywin32 to control internet explorer or something similar, like using the webkit-browser from pyqt4 or even using telnet and mozrepl (this seems really hard) Switching language to perl since www::Mechanize seems be a lot more mature on per (addons and such for javascript). Don't know too much about this at all. If anyone has some pointers here that would be great. I understand that I need to do a lot of trial and error, but would be nice I wouldn't go too far away from the "true" answer, if there is such a thing.
Options for handling javascript heavy pages while screen scraping
0
0
1
795
3,929,228
2010-10-14T00:48:00.000
6
0
1
0
python,import,module
3,929,323
1
true
0
0
I think that instead of from pack1.mod2 you actually want to say from lib.pack1.mod2. Edit: and, specifying what version of Python this is would help, since importation semantics have improved gradually over the years! Edit: Aha! Thank you for your comment; I now understand. You are trying to rename libraries without going inside of them and fixing the fact that their name is now different. The problem is that what you are doing is, unfortunately, impossible. If all libraries used relative imports inside, then you might have some chance of doing it; but, alas, relative imports are both (a) recent and (b) not widely used. So, if you want to use library p, then you are going to have to put it in your root directory, not inside of lib/p because that creates a library with a different name: lib.p, which is going to badly surprise the library and break it. But I have two more thoughts. First, if you are trying to do this to organize your files, and not because you need the import names to be different, then (a) create lib like you are doing but (b) do not put an __init__.py inside! Instead, add the lib directory to your PYTHONPATH or, inside of your program, to sys.path. (Does the GAE let you do something like this? Does it have a PYTHONPATH?) Second, I am lying when I say this is not possible. Strictly speaking, you could probably do this by adding an entry to sys.metapath that intercepts all module lookups and tries grabbing them from inside of lib if they exist there. But — yuck.
1
1
0
I'm trying to import a few libraries into my program (which is a google AppEngine application). Basically, I'm supposed to put all libraries in the root folder, but I've just created another folder called lib and placed them within that folder. (I've created the __init__.py) Imports regularly work fine by using the import lib.module or from lib import module, but what happens is that when I try to import a complete package, for instance a folder named pack1 with various modules in it, by calling from lib.pack1 import *, I get this error in one of the modules who has accessed another module statically, i.e. from pack1.mod2 import sth. What is the easy and clean way to overcome this? Without modifying the libraries themselves. Edit: Using Python 2.7. Edit: Error: when using import lib.pack1, I get ImportError: No module named pack1.mod1.
Importing nested modules in Python
1.2
0
0
4,776
3,929,278
2010-10-14T01:00:00.000
53
1
1
0
python
43,015,990
10
false
0
0
When used with sets it performs union operation.
2
183
0
Google won't let me search |= so I'm having trouble finding relevant documentation. Anybody know?
What does |= (ior) do in Python?
1
0
0
124,921
3,929,278
2010-10-14T01:00:00.000
2
1
1
0
python
51,221,579
10
false
0
0
In Python,|=(ior) works like union operation. like if x=5 and x|=5 then both the value will first convert in binary value then the union operation will perform and we get the answer 5.
2
183
0
Google won't let me search |= so I'm having trouble finding relevant documentation. Anybody know?
What does |= (ior) do in Python?
0.039979
0
0
124,921
3,930,129
2010-10-14T04:38:00.000
0
0
0
0
python,facebook
4,663,777
2
false
1
0
There's a getLoginUrl in the facebook SDK. You might want to look at that. -Roozbeh
1
2
0
I am trying to make an app for authenticating user with their facebook account in python. App opens the facebook login page in web browser. After user logs in, facebook redirects it to thei dummy success page. At that moment i need to capture that redirect url in my app. I am not able to catch that URL. I am opening fb login page by using webbrowser.open . How can i catch the redirect url after opening web browser? Any suggestions will be very helpful. Thanks, Tara Singh
Catching the Access Token sent by Facebook after successful authentication
0
0
1
755
3,930,422
2010-10-14T05:45:00.000
41
1
1
0
python,unit-testing,nose,nosetests,pycharm
13,359,250
3
true
0
0
In the current version of Pycharm (2.6) there should be a context menu "run Nosetests in ..." on a test file. If this is missing, go to file->settings->Project Settings->python integrated tools and ensure the Default Test Runner is Nosetests. You do of course need to have Nosetests installed - pycharm will offer this if you do not. This does have a limitation. If the file in question does not have a class derived from unittest.TestCase it will not automatically show this. If you are using nose.tools or simple assertions it will not automatically offer this. This is probably a bug.
2
30
0
How do you execute nosetest from pycharm to run all unit tests? I know that pycharm supports python's unittest and py.test and that they will properly support nosetests in pycharm 1.1 but I was wondering if there was a work around.
How do you run nosetest from pycharm?
1.2
0
0
20,545
3,930,422
2010-10-14T05:45:00.000
2
1
1
0
python,unit-testing,nose,nosetests,pycharm
3,931,985
3
false
0
0
If you can live without the graphical test runner, you can simply create a "Python Script" run configuration and run the tests as you run them from the command line. The only way to get nose tests working with the graphical test runner, I'm afraid, is to hack on helpers/pycharm/utrunner.py from the PyCharm distribution.
2
30
0
How do you execute nosetest from pycharm to run all unit tests? I know that pycharm supports python's unittest and py.test and that they will properly support nosetests in pycharm 1.1 but I was wondering if there was a work around.
How do you run nosetest from pycharm?
0.132549
0
0
20,545
3,931,178
2010-10-14T08:00:00.000
2
0
1
0
python
7,136,383
2
false
0
0
Using space for separating options has the disadvantage that if space is already present in the options, as in the case of file names, it wont work. So better to use comma and split using .split(',') and remove leading/trailing whitespaces.
1
0
0
I have made a Config file and have multiple values for a keyword as: [section] database: mysql , sqlite and i want to access the values separately..How to go about it??
How to read muliple values from a config file using config parser
0.197375
0
0
792
3,931,951
2010-10-14T09:49:00.000
14
0
0
0
python,postgresql,sqlalchemy,psycopg2,vacuum
3,932,055
2
true
0
0
This is a flaw in the Python DB-API: it starts a transaction for you. It shouldn't do that; whether and when to start a transaction should be up to the programmer. Low-level, core APIs like this shouldn't babysit the developer and do things like starting transactions behind our backs. We're big boys--we can start transactions ourself, thanks. With psycopg2, you can disable this unfortunate behavior with an API extension: run connection.autocommit = True. There's no standard API for this, unfortunately, so you have to depend on nonstandard extensions to issue commands that must be executed outside of a transaction. No language is without its warts, and this is one of Python's. I've been bitten by this before too.
1
9
0
Well, the question pretty much summarises it. My db activity is very update intensive, and I want to programmatically issue a Vacuum Analyze. However I get an error that says that the query cannot be executed within a transaction. Is there some other way to do it?
Is it possible to issue a "VACUUM ANALYZE " from psycopg2 or sqlalchemy for PostgreSQL?
1.2
1
0
5,030
3,933,923
2010-10-14T13:56:00.000
2
0
1
0
python,ubuntu,numpy
3,934,387
2
false
0
0
One way to try, which isn't guaranteed to work, but worth a shot is to see if uupdate can sucessfully update the package. Get a tarball of numpy 1.5. run "apt-get source numpy" which should fetch and unpack the current source from ubuntu. cd into this source directory and run "uupdate ../numpytarballname". This should update the old source package using the newer tarball. then you can try building with "apt-get build-dep numpy" and "dpkg-buildpackage -rfakeroot". This will require you have the build-essential and fakeroot packages installed.
1
0
1
How do I build numpy 1.5 on ubuntu 10.10? The instructions I found seems outdated or not clear. Thanks
build recent numpy on recent ubuntu
0.197375
0
0
1,563
3,937,456
2010-10-14T20:51:00.000
1
0
0
0
python,openid,store
3,937,506
1
true
0
0
upd.: my previous answer was wrong The store you are referring to is where your app stores the data during auth. Storing it in a shared memcached instance should be the best option (faster than db and reliable enough).
1
3
0
Hi so this is what I understand how Openid works:- the user enters his openid url on the site say"hii.com" The app does a redirect to the openid provider and either does the login or denies it and sends the response back to the site i.e"hii.com" If authentication was succesful then the response object provided by the openid provider can contain other data too like email etc if "hii.com" had requested for it. I can save this data in the database. Please correct me if I am wrong. However what I am not understanding here is the concept of stores. I see openid.store.filestore,nonce,sqlstore. Could someone please provide some clarity on it. What role does this store play here. I have gone through python openid docs but end up feeling clueless. Thanks
what is the concept of store in OpenID
1.2
1
0
488
3,939,482
2010-10-15T04:22:00.000
1
0
0
1
python
3,939,511
3
true
0
0
It doesn't really answer your question, but there isn't really anything wrong with calling os.system to clear out the terminal (other than the system running on different operating systems) in which case you could use: os.system('cls' if os.name=='nt' else 'clear')
1
2
0
I have a stats app written in python that on a timer refreshes the ssh screen with stats. Right now it uses os.system('clear') to clear the screen and then outputs a multi line data with the stats. I'd like to do just do a \r instead of executing the clear but that only works with one line, is it possible to do this with multiple lines? A classic example of what I want to do is when you execute the "top" command which lists the current processes it updates the screen without executing the "clear" and it's got many lines. Anyone have any tips for this?
python - multi line stdout refresh issue
1.2
0
0
1,629
3,939,877
2010-10-15T06:11:00.000
12
0
1
0
python,django,eclipse,pydev
3,941,289
10
true
1
0
go in the menu to window -> preference -> pydev -> Interpreter - Python ; and add the python interpreter there, if you installed the django in a virtual environment you should add the python interpreter of the virtual env ; after adding the interpreter by clicking on new you should now click on Apply , you should see now all the system libs from PYTHONPATH added there between them Django . hope this will help
10
15
0
I have python installed with django. I know the installation is there because I installed it following the directions and in the command line I can do "import python" and there is no crash. When I try creating a django project in pydev, I get an error: "Django not found." What could the problem be?
pydev not recognizing python installation with django
1.2
0
0
11,629
3,939,877
2010-10-15T06:11:00.000
6
0
1
0
python,django,eclipse,pydev
4,118,703
10
false
1
0
Jaffa, You might have configured your python interpreter in Eclipse prior to installing Django in python. So what you have to do now is in Eclipse remove the Python interpreter and add it again (now that it has Django installed) and all should work ok.
10
15
0
I have python installed with django. I know the installation is there because I installed it following the directions and in the command line I can do "import python" and there is no crash. When I try creating a django project in pydev, I get an error: "Django not found." What could the problem be?
pydev not recognizing python installation with django
1
0
0
11,629
3,939,877
2010-10-15T06:11:00.000
0
0
1
0
python,django,eclipse,pydev
28,459,588
10
false
1
0
Same problem I have faced today. I took help from these answer. but in my case it didnt work. There is small modification in @antonkeren answer. 1) Go to Preferences. Windows > preferences. 2) Search for Pydev 3) Select Python Interpreter 4) Pressed Quick Auto-config 5) now download www.djangoproject.org/downloads django tar and extract on any location. 6) now click on Folder in "Libraries tab" of "System PYTHONPATH" and select your extracted django project folder location. 7) Click on apply and ok. Creating a Django project afterwards should be ok. Cheers...!!
10
15
0
I have python installed with django. I know the installation is there because I installed it following the directions and in the command line I can do "import python" and there is no crash. When I try creating a django project in pydev, I get an error: "Django not found." What could the problem be?
pydev not recognizing python installation with django
0
0
0
11,629
3,939,877
2010-10-15T06:11:00.000
1
0
1
0
python,django,eclipse,pydev
3,943,039
10
false
1
0
I stumbled upon this only yesterday myself: Django must not be among the system libraries for this to function...
10
15
0
I have python installed with django. I know the installation is there because I installed it following the directions and in the command line I can do "import python" and there is no crash. When I try creating a django project in pydev, I get an error: "Django not found." What could the problem be?
pydev not recognizing python installation with django
0.019997
0
0
11,629
3,939,877
2010-10-15T06:11:00.000
0
0
1
0
python,django,eclipse,pydev
4,049,594
10
false
1
0
I think I've got the same problem, Eclipse 3.5.2 on Fedora. In my PyDev Python interpreter settings I've got the site-packages/django folder (site-packages/django/bin too, just in case), but when I try to create a django project I get an error dialogue saying "It seems that the selected interpreter does not have Django available". Looks like I'm going to have to use Eric4, which is a pity because I can't get that working at all on my Windows rig! Unless I manage to understand the cryptic advice above, "Django must not be among the system libraries for this to function..."
10
15
0
I have python installed with django. I know the installation is there because I installed it following the directions and in the command line I can do "import python" and there is no crash. When I try creating a django project in pydev, I get an error: "Django not found." What could the problem be?
pydev not recognizing python installation with django
0
0
0
11,629
3,939,877
2010-10-15T06:11:00.000
21
0
1
0
python,django,eclipse,pydev
4,241,222
10
false
1
0
I had the same problem and this is what I did just after installing eclipse: Preferences > Interpreter Python Pressed Auto-config Selected /Library/Python/x.x/site-packages, which was not selected (some django folders were in there, persumably the installation) Clicked apply / OK Creating a Django project afterwards should be ok. Good Luck!
10
15
0
I have python installed with django. I know the installation is there because I installed it following the directions and in the command line I can do "import python" and there is no crash. When I try creating a django project in pydev, I get an error: "Django not found." What could the problem be?
pydev not recognizing python installation with django
1
0
0
11,629
3,939,877
2010-10-15T06:11:00.000
1
0
1
0
python,django,eclipse,pydev
4,563,129
10
false
1
0
Use auto config in the preferences option and then click apply and then ok.
10
15
0
I have python installed with django. I know the installation is there because I installed it following the directions and in the command line I can do "import python" and there is no crash. When I try creating a django project in pydev, I get an error: "Django not found." What could the problem be?
pydev not recognizing python installation with django
0.019997
0
0
11,629
3,939,877
2010-10-15T06:11:00.000
1
0
1
0
python,django,eclipse,pydev
4,961,144
10
false
1
0
If everything is done as said above, and still showing "Django not found" while your are trying to create django project, let try to double click 'django-admin' python file that in scripts folder of python. And try to create django project
10
15
0
I have python installed with django. I know the installation is there because I installed it following the directions and in the command line I can do "import python" and there is no crash. When I try creating a django project in pydev, I get an error: "Django not found." What could the problem be?
pydev not recognizing python installation with django
0.019997
0
0
11,629
3,939,877
2010-10-15T06:11:00.000
2
0
1
0
python,django,eclipse,pydev
5,612,184
10
false
1
0
I was having this same exact problem today, and I just wanted to add some notes to help people out. You can follow the instructions of antonkeren above, but there's one thing to note that was not mentioned. After adding the django directory to the path you must QUIT ECLIPSE OR APTANA STUDIO. After you restart it and try to create a django project it will work.
10
15
0
I have python installed with django. I know the installation is there because I installed it following the directions and in the command line I can do "import python" and there is no crash. When I try creating a django project in pydev, I get an error: "Django not found." What could the problem be?
pydev not recognizing python installation with django
0.039979
0
0
11,629
3,939,877
2010-10-15T06:11:00.000
1
0
1
0
python,django,eclipse,pydev
4,438,527
10
false
1
0
I had the same problem and had solved it by adding the python home directory to the PATH variable and reconfigure the python interpreter on pydev.
10
15
0
I have python installed with django. I know the installation is there because I installed it following the directions and in the command line I can do "import python" and there is no crash. When I try creating a django project in pydev, I get an error: "Django not found." What could the problem be?
pydev not recognizing python installation with django
0.019997
0
0
11,629
3,939,912
2010-10-15T06:18:00.000
0
0
1
0
python,performance,intel
3,939,973
3
false
0
0
Consider repeating on regular HDD's - that SSD could well result in a substantial performance difference depending on caches, and the nature of that data.
2
4
0
I am running a program that does simple data processing: parses text populates dictionaries calculates some functions over the resulting data The program only uses CPU, RAM, and HDD: run from Windows command line input/output to the local hard drive nothing displayed on or printed to screen no networking The same program is run on: desktop: Windows 7, i7-930 CPU overclocked @3.6 GHz (with matching memory speed), Intel X-25M SSD laptop: Windows XP, Intel Core2 Duo T9300 @2.5GHz, 7200 rpm HDD The CPU is 1.44 faster frequency, HDD is 4 times higher benchmark score (Passmark - Disk Mark). I found the program runs just around 1.66 times faster on the desktop. So apparently, the CPU is the bottleneck. It seems there's only 15% benefit from the i7 Core vs Intel Core2 Duo architecture (most of the performance boost is due to the straight CPU frequency). Is there anything I can do in the code to increase the benefit of the new architecture? EDIT: forgot to mention that I use ActivePython 3.1.2 if that matters.
Python execution speed: laptop vs desktop
0
0
0
1,614
3,939,912
2010-10-15T06:18:00.000
0
0
1
0
python,performance,intel
3,939,957
3
false
0
0
Split your processing into multiple threads. Your particular i7 should be able to support up to 8 threads in parallel.
2
4
0
I am running a program that does simple data processing: parses text populates dictionaries calculates some functions over the resulting data The program only uses CPU, RAM, and HDD: run from Windows command line input/output to the local hard drive nothing displayed on or printed to screen no networking The same program is run on: desktop: Windows 7, i7-930 CPU overclocked @3.6 GHz (with matching memory speed), Intel X-25M SSD laptop: Windows XP, Intel Core2 Duo T9300 @2.5GHz, 7200 rpm HDD The CPU is 1.44 faster frequency, HDD is 4 times higher benchmark score (Passmark - Disk Mark). I found the program runs just around 1.66 times faster on the desktop. So apparently, the CPU is the bottleneck. It seems there's only 15% benefit from the i7 Core vs Intel Core2 Duo architecture (most of the performance boost is due to the straight CPU frequency). Is there anything I can do in the code to increase the benefit of the new architecture? EDIT: forgot to mention that I use ActivePython 3.1.2 if that matters.
Python execution speed: laptop vs desktop
0
0
0
1,614
3,940,057
2010-10-15T06:45:00.000
1
1
0
0
python,snmp,fitnesse,net-snmp,pysnmp
3,968,271
1
true
0
0
The engineTime and engineBoots values are probably what is messing you up because SNMPv3 requires they not go backwards. If you have an agent that is restarting from scratch and not incrementing it's boots count (which is illegal, but under tests I could see why you'd be doing that) then you'd need to reset the internal notion of boots and time. However, setting them to 0 and 0 won't help because it'll assume those are defaults. You should, instead, change one of them to '1' which should trigger the override clause to actually use the values. Set the time to 1 and try it and I think it'll work (and if it doesn't, set them both to 1 instead and try that).
1
1
0
I'm trying to create automated integration tests for this hardware+software test subject which runs a SNMP agent as it's command interface. Our test setup looks like this: We're using Fitnesse as a test runner and PyFit to be able to write the tests in Python. We then use netsnmp with Python bindings to send SNMP commands. This works pretty well. However, when I try to run a suite the SNMP agent (the test subject) is restarted (and usually at a different simulated time) which makes the internals of netsnmp get all sorts of interesting errors. Turns out there is a lot of global state stored inside the netsnmp library like community and context names and problematically EngineTime and EngineBootCnt, which is used to prevent replay attacks in SNMP v3. This causes the agent to reject my snmp commands. My problems is how do I reinitialise the netsnmp library (from the Python bindings) in a way that the internal global state are reset? The netsnmp.Session object in the Python bindings do take the parameter EngineTime and EngineBoots and setting them to 0 should reset them, but actually it doesn't seem to do that. I also do not know if there is other global state in there which needs to be reset. I'm at a point where I think I need to rewrite the tests to use the pure python snmp library pysnmp, but I was hoping to avoid it.
Resetting all global internal state of the net-snmp library from the Python bindings
1.2
0
0
731
3,940,098
2010-10-15T06:53:00.000
0
0
0
0
python,google-app-engine,screenshot
3,940,121
5
false
1
0
It's certainly technically possible. You would probably have to render the HTML directly onto an image file (or more likely, onto an in-memory bitmap that's written to an image file once completed). I don't know any libraries to do this for you (apart from a modified WebKit, perhaps)... but there's certainly websites that do this. Of course, this is a bit more involved than just opening the page in a browser on a machine and taking a screenshot programatically, but the result would likely be better if you don't care about the result from a specific browser.
1
6
0
Do you think is technically possible to take a screeshot of a website programmatically? I would like to craft a scheduled Python task that crawls a list of websites taking an homepage screenshot of them. Do you think is technically feasible or do you know third party website that offer a service like that (Input: url --> Output: screenshot) ? Any suggestion?
Is it technically possible to take a screenshot of a website programmatically?
0
0
1
2,523
3,940,774
2010-10-15T08:53:00.000
1
1
0
0
python,oauth,twitter
3,940,860
2
true
0
0
Yes, thats right. You need to register it and connect "grant access" it with your twitter id, if you want, for example, post something on your twitter wall. Also see "connections" in your twitter id.
2
1
0
I'm unfamiliar with the new oauth system. I wanted to crawl the status updates of my friends, and their friends' (if permissions allow) with my specified account credentials using the python-twitter api. With the new oauth authentication, does it means that I have to first register an application with twitter before I can use api?
noob question regarding twitter oauth
1.2
0
1
206
3,940,774
2010-10-15T08:53:00.000
0
1
0
0
python,oauth,twitter
3,940,840
2
false
0
0
For use api you must register your aplication or use GET methods to post into twi through web interface.
2
1
0
I'm unfamiliar with the new oauth system. I wanted to crawl the status updates of my friends, and their friends' (if permissions allow) with my specified account credentials using the python-twitter api. With the new oauth authentication, does it means that I have to first register an application with twitter before I can use api?
noob question regarding twitter oauth
0
0
1
206
3,941,830
2010-10-15T11:36:00.000
3
0
1
0
python,py2exe
3,941,876
4
false
0
0
Python programs need python to run. All py2exe does is to include full python and all libraries you use together with your script in a single file.
3
1
0
whenever i build python file to exe file from py2exe, it takes lots of space of minimum 25MB for small project also,it includes all the the python library file. Is there any other way that i can reduce the size.
python windows standalone exe file
0.148885
0
0
1,131
3,941,830
2010-10-15T11:36:00.000
0
0
1
0
python,py2exe
3,941,907
4
false
0
0
py2exe tends to err on the side of caution. You can manually exclude some libraries with the exclude list option in order to reduce the size of the file. In my experience, you should be able to compress down to a ~9 MB installer (Inno) if you include wxPython or another GUI framework, ~7 MB if you ship a console app or use tkinter.
3
1
0
whenever i build python file to exe file from py2exe, it takes lots of space of minimum 25MB for small project also,it includes all the the python library file. Is there any other way that i can reduce the size.
python windows standalone exe file
0
0
0
1,131
3,941,830
2010-10-15T11:36:00.000
-2
0
1
0
python,py2exe
3,941,866
4
false
0
0
No, not really; you need Python shipped with the exe so that it is standalone. It it not common to create exe Files from Python projects, anyway.
3
1
0
whenever i build python file to exe file from py2exe, it takes lots of space of minimum 25MB for small project also,it includes all the the python library file. Is there any other way that i can reduce the size.
python windows standalone exe file
-0.099668
0
0
1,131
3,943,106
2010-10-15T14:18:00.000
3
0
1
0
python,thread-safety,multicore,embedding,embedded-language
3,943,160
2
false
0
0
If you're CPU bound, Python can only scale to multiple core using the multiprocessing library. However, if you're I/O bound, then threading is usually sufficient. If you want easy thread safety, then use Queue for all message passing.
1
1
0
I'm trying to use Python in a module for an analysis software of vehicle bus systems. For this I have to embed Python in a thread safe manner, since there can be multiple instances of the module witch work independently. I could use a mutex to guard all access to Python and create an unique (python) module for every thread. Obviously this is the easiest way out but comes with the price of not being able to scale across multiple cores. Or I could modify my module to spawn new processes which intern uses Python and connect to them via shared memory. This gives me a performance penalty and costs more time to implement but scales great. My question: witch one do you think makes more sense? Is there any other way to embed Python thread safe or even in a way that scales over multiple cores. Kind regards Moritz edit: I'm using CPython
Embedding Python thread safe
0.291313
0
0
912
3,943,598
2010-10-15T15:16:00.000
0
0
0
0
python,django,sysadmin
3,943,924
2
false
1
0
I think you're pretty much covering everything. Identify what's important to you and you're business practices: that's what counts.
1
0
0
Does anyone have or know of a good template / plan for doing automated server upgrades? In this case I am upgrading a python/django server, but am going to have to apply this update to many machines, and want to be sure that the operation is fully testable and recoverable should anything go wrong. Am picturing something along the lines of: remotely fetch new code verify code download (e.g. hash of files) take down server, display "you are upgrading dialog" backup database(s) backup code directory apply new code updates verify code update (e.g. hash of files) apply database update (if necessary) run tests if success startup server verify server update else restore old database restore old code report error startup server verify server restore I'm sure that this isn't exhaustive, and there are many other error conditions to consider, but am wondering if something like this already exists as a formalized process/best practices checklist to follow? Ideally this whole thing should of course be done by a single script call.
Server Upgrade Script
0
0
0
88
3,943,808
2010-10-15T15:43:00.000
5
1
0
0
java,python,unit-testing
3,944,260
3
false
1
0
Python unit tests do check types. All the time. In fact, that's the only thing they are doing. Python is duck-typed. Duck typing means that the type of an object is defined by its behavior. Unit tests test behavior. Ergo, they test types.
1
3
0
I was going through a few tests written in Java using JUnit and I could'nt help noticing the emphasis which is laid on checking the "type" of objects. This is something I have never seen in Python test-suites. Java being statically-typed and Python being dynamically-typed, should'nt the reverse be the case?
Python unittests almost never check types
0.321513
0
0
187
3,945,750
2010-10-15T20:11:00.000
9
0
0
0
python,beautifulsoup
45,193,575
2
false
1
0
with bs4 things have changed a little. so the code should look like this soup = BeautifulSoup(htmlstring,'lxml') soup.find_all('div', {'style':"width=300px;"})
1
29
0
I can traverse generic tags easily with BS, but I don't know how to find specific tags. For example, how can I find all occurances of <div style="width=300px;">? Is this possible with BS?
Find a specific tag with BeautifulSoup
1
0
1
62,029
3,945,924
2010-10-15T20:35:00.000
18
0
1
0
python,this,self
3,945,938
2
true
0
0
Yes it is legal, and yes it is pythonic. I find myself using this pattern when you have an object and a container object where the contained objects need to know about their parent.
1
12
0
I recently was working on a little python project and came to a situation where I wanted to pass self into the constructor of another object. I'm not sure why, but I had to look up whether this was legal in python. I've done this many times in C++ and Java but I don't remember ever having to do this with python. Is passing references to self to new objects something that isn't considered pythonic? I don't think I've seen any python programs explicitly passing self references around. Have I just happen to not have a need for it until now? Or am I fighting python style?
Passing self into a constructor in python
1.2
0
0
5,745
3,945,940
2010-10-15T20:37:00.000
15
0
1
0
python,list,subclassing
3,946,763
4
true
0
0
There are no benefits to subclassing list. None of the methods will use any methods you override, so you can have unexpected bugs. Further, it's very often confusing doing things like self.append instead of self.foos.append or especially self[4] rather than self.foos[4] to access your data. You can make something that works exactly like a list or (better) howevermuch like a list you really want while just subclassing object.
3
17
0
I was recently going over a coding problem I was having and someone looking at the code said that subclassing list was bad (my problem was unrelated to that class). He said that you shouldn't do it and that it came with a bunch of bad side effects. Is this true? I'm asking if list is generally bad to subclass and if so, what are the reasons. Alternately, what should I consider before subclassing list in Python?
What to consider before subclassing list?
1.2
0
0
9,358
3,945,940
2010-10-15T20:37:00.000
6
0
1
0
python,list,subclassing
3,946,030
4
false
0
0
Nick is correct. Also, while I can't speak to Python, in other OO languages (Java, Smalltalk) subclassing a list is a bad idea. Inheritance in general should be avoided and delegation-composition used instead. Rather, you make a container class and delegate calls to the list. The container class has a reference to the list and you can even expose the calls and returns of the list in your own methods. This adds flexibility and allows you to change the implementation (a different list type or data structure) later w/o breaking any code. If you want your list to do different listy-type things then your container can do this and use the plain list as a simple data structure. Imagine if you had 47 different uses of lists. Do you really want to maintain 47 different subclasses? Instead you could do this via the container and interfaces. One class to maintain and allow people to call your new and improved methods via the interface(s) with the implementation remaining hidden.
3
17
0
I was recently going over a coding problem I was having and someone looking at the code said that subclassing list was bad (my problem was unrelated to that class). He said that you shouldn't do it and that it came with a bunch of bad side effects. Is this true? I'm asking if list is generally bad to subclass and if so, what are the reasons. Alternately, what should I consider before subclassing list in Python?
What to consider before subclassing list?
1
0
0
9,358
3,945,940
2010-10-15T20:37:00.000
11
0
1
0
python,list,subclassing
3,945,953
4
false
0
0
I think the first question I'd ask myself is, "Is my new object really a list?". Does it walk like a list, talk like a list? Or is is something else? If it is a list, then all the standard list methods should all make sense. If the standard list methods don't make sense, then your object should contain a list, not be a list. In old python (2.2?) sub-classing list was a bad idea for various technical reasons, but in a modern python it is fine.
3
17
0
I was recently going over a coding problem I was having and someone looking at the code said that subclassing list was bad (my problem was unrelated to that class). He said that you shouldn't do it and that it came with a bunch of bad side effects. Is this true? I'm asking if list is generally bad to subclass and if so, what are the reasons. Alternately, what should I consider before subclassing list in Python?
What to consider before subclassing list?
1
0
0
9,358
3,946,219
2010-10-15T21:16:00.000
2
0
0
0
python,statistics,numpy,stata
4,572,785
5
false
0
0
Use Rpy2 and call the R var package.
2
9
1
Some coworkers who have been struggling with Stata 11 are asking for my help to try to automate their laborious work. They mainly use 3 commands in Stata: tsset (sets a time series analysis) as in: tsset year_column, yearly varsoc (Obtain lag-order selection statistics for VARs) as in: varsoc column_a column_b vec (vector error-correction model) as in: vec column_a column_b, trend(con) lags(1) noetable Does anyone know any scientific library that I can use through python for this same functionality?
Migrating from Stata to Python
0.07983
0
0
1,936
3,946,219
2010-10-15T21:16:00.000
0
0
0
0
python,statistics,numpy,stata
3,946,648
5
false
0
0
I have absolutely no clue what any of those do, but NumPy and SciPy. Maybe Sage or SymPy.
2
9
1
Some coworkers who have been struggling with Stata 11 are asking for my help to try to automate their laborious work. They mainly use 3 commands in Stata: tsset (sets a time series analysis) as in: tsset year_column, yearly varsoc (Obtain lag-order selection statistics for VARs) as in: varsoc column_a column_b vec (vector error-correction model) as in: vec column_a column_b, trend(con) lags(1) noetable Does anyone know any scientific library that I can use through python for this same functionality?
Migrating from Stata to Python
0
0
0
1,936
3,947,313
2010-10-16T01:46:00.000
-2
0
0
1
python
3,947,329
4
false
0
0
Generally ls -la is in bytes. If you want it in "human readable" form, use the command ls -alh.
1
31
0
I want to delete all files in a folder that are less than 200 kB in size. Just want to be sure here, when i do a ls -la on my macbook, the file size says 171 or 143, I am assuming this is kb correct?
Python script to loop through all files in directory, delete any that are less than 200 kB in size
-0.099668
0
0
52,290
3,947,443
2010-10-16T02:36:00.000
2
0
0
1
python,google-app-engine,performance,wing-ide
3,957,947
2
true
1
0
Probably because you've got a debugger hooked up - debuggers slow code down a lot by instrumenting everything, and deserializing your datastore is a lot of work. Using the --use_sqlite flag will enable an experimental sqlite-based local datastore, which should require less startup time. Note that it'll require you to wipe your datastore when you switch to it, however.
1
1
0
I'm developing on Google App Engine. I am using WingIDE (a python IDE) to debug on the development server. I have several thousand entities in my datastore and I can see that when the development server starts up, it has to go through DatastoreFileStub.Read() and do something which each entity. The problem is, when I run the development server through WingIDE it runs horrendously slow. I put some profiling logging code into the google app engine to take a peak. When I run the development server on the command line, I get the following message: Finished reading 10374 Entites in 10.17 seconds, 1019 per second When I run the development server through WingIDE however, I get this: Finished reading 10374 Entites in 52.44 seconds, 197 per second Anyone have an idea why WingIDE would be 5 times slower?
Google App Engine development server is slow to start up when using WingIDE
1.2
0
0
713
3,948,257
2010-10-16T09:07:00.000
0
0
1
0
python,indentation,python-idle
3,948,671
5
false
0
0
textmate (and maybe e?): select then apple-] bbedit: also select then apple-] emacs: select then M-x 'indent-region' bpython: don't know, autoindenting is so easy in bpython, you'd have to work to break it xcode: don't do python in xcode that's generally all I need to know. also yeah it's easy to slap a brace above or below a poorly indented block, but you know it's just going to confuse the shit out of you a week later when you haven't been staring at it for like a day. srsly u guys.
3
3
0
In Python, what do you do when you write 100 lines of code and forget to add a bunch of loop statements somewhere? I mean, if you add a while statement somewhere, you've to now indent all the lines below it. It's not like you can just put braces and be done with it. Go to every single line and add tabs/spaces. What if you were adding nested loops/if/then statements to existing code? Am I missing some shortcut?
Python indentation when adding looping statements to existing code
0
0
0
4,202
3,948,257
2010-10-16T09:07:00.000
11
0
1
0
python,indentation,python-idle
3,948,270
5
false
0
0
I think every serious editor or IDE supports the option to select multiple lines and press tab to indent or Shift-Tab to unindent all that lines.
3
3
0
In Python, what do you do when you write 100 lines of code and forget to add a bunch of loop statements somewhere? I mean, if you add a while statement somewhere, you've to now indent all the lines below it. It's not like you can just put braces and be done with it. Go to every single line and add tabs/spaces. What if you were adding nested loops/if/then statements to existing code? Am I missing some shortcut?
Python indentation when adding looping statements to existing code
1
0
0
4,202
3,948,257
2010-10-16T09:07:00.000
3
0
1
0
python,indentation,python-idle
3,948,313
5
false
0
0
in IDLE, the standard python IDE, select the code, go on 'format' and you can chooose indent region, dedent region and so on
3
3
0
In Python, what do you do when you write 100 lines of code and forget to add a bunch of loop statements somewhere? I mean, if you add a while statement somewhere, you've to now indent all the lines below it. It's not like you can just put braces and be done with it. Go to every single line and add tabs/spaces. What if you were adding nested loops/if/then statements to existing code? Am I missing some shortcut?
Python indentation when adding looping statements to existing code
0.119427
0
0
4,202
3,949,739
2010-10-16T16:33:00.000
0
0
0
0
python,html
5,693,726
2
false
1
0
urllib.unquote() on its own may still cause problems by throwing the exception: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position n: ordinal not in range(128) In that case try: print urllib.unquote("Ober%C3%B6sterreich.txt").decode("utf8")
1
0
0
I always found links in html source stored in such format, the question is how do I change such links back to what it's normally like? Thanks a lot!
How to turn an encoded link such as "http%3A%2F%2Fexample.com%2Fwhatever" into "http://example.com/whatever" in python?
0
0
1
797
3,949,842
2010-10-16T17:01:00.000
-1
0
0
0
python,user-interface,pyqt4
11,305,421
2
false
0
1
winBase, winForm = uic.loadUiType("mainWindow.ui") # this is the file created whith Qt Designer class Window(winBase, winForm): def __init__(self, parent = None) super(winBase, self).__init__(parent) self.setupUi(self)
1
0
0
I am new to the world of PyQt.I am using PyQt designer for designing the UI and coding to provide functionality in it.But unfortunately I am getting confused to link with the UI.By importing the class we generally doing in examples.But when I try my own code its not happening. Any hints for how designer and other parts interacts will be super helpful. Thanks in advance!
PyQt GUI based CRUD application
-0.099668
0
0
1,463
3,950,607
2010-10-16T20:20:00.000
7
0
0
1
python,multithreading,io,blocking,nonblocking
3,950,630
1
true
0
0
Since you're I/O bound, then use the threading module. You should almost never need to use thread, it's a low-level interface; the threading module is a high-level interface wrapper for thread. The multiprocessing module is different from the threading module, multiprocessing uses multiple subprocesses to execute a task; multiprocessing just happens to use the same interface as threading to reduce learning curve. multiprocessing is typically used when you have CPU bound calculation, and need to avoid the GIL (Global Interpreter Lock) in a multicore CPU. A somewhat more esoteric alternative to multi-threading is asynchronous I/O using asyncore module. Another options includes Stackless Python and Twisted.
1
6
0
I have a Python application that, to be brief, receives data from a remote server, processes it, responds to the server, and occasionally saves the processed data to disk. The problem I've encountered is that there is a lot of data to write, and the save process can take upwards of half a minute. This is apparently a blocking operation, so the network IO is stalled during this time. I'd like to be able to make the save operation take place in the background, so-to-speak, so that the application can continue to communicate with the server reasonably quickly. I know that I probably need some kind of threading module to accomplish this, but I can't tell what the differences are between thread, threading, multiprocessing, and the various other options. Does anybody know what I'm looking for?
What threading module should I use to prevent disk IO from blocking network IO?
1.2
0
1
1,332
3,950,687
2010-10-16T20:39:00.000
77
0
0
0
python,tkinter
3,950,766
3
true
0
1
Use somewidget.winfo_width() and somewidget.winfo_height() to get the actual widget size, the somewidget['width'] property is only a hint given to the geometry manager.
3
62
0
I'm using Python and Tkinter, and I need to know the current dimensions (width, height) of a widget. I've tried somewidget["width"], but it returns only a fixed value, and is not updated whenever the widget size changes (e.g. when the window is resized).
How to find out the current widget size in tkinter?
1.2
0
0
81,835
3,950,687
2010-10-16T20:39:00.000
82
0
0
0
python,tkinter
49,216,638
3
false
0
1
somewidget.winfo_width() and somewidget.winfo_height() give 1. You need to update Tk (issue tk.update()) before getting these values.
3
62
0
I'm using Python and Tkinter, and I need to know the current dimensions (width, height) of a widget. I've tried somewidget["width"], but it returns only a fixed value, and is not updated whenever the widget size changes (e.g. when the window is resized).
How to find out the current widget size in tkinter?
1
0
0
81,835
3,950,687
2010-10-16T20:39:00.000
13
0
0
0
python,tkinter
60,086,946
3
false
0
1
You can use the function somewidget.winfo_reqheight() for height and somewidget.winfo_reqwidth() for width, but first don't forget to call the update function of the widget you want to know the dimension somewidget.update(). If you do not call the update function you will get the default value 1.
3
62
0
I'm using Python and Tkinter, and I need to know the current dimensions (width, height) of a widget. I've tried somewidget["width"], but it returns only a fixed value, and is not updated whenever the widget size changes (e.g. when the window is resized).
How to find out the current widget size in tkinter?
1
0
0
81,835
3,950,851
2010-10-16T21:21:00.000
0
1
0
0
python,django,internationalization,project-planning
3,970,432
2
false
1
0
One big change in your project: you need to build in time to localize your strings. Depending on your schedules, you may have to rearrange work so that all the string-changing work is at the front so that you have time to get the translations done before launching. Or, alternately, you have to build in a buffer at the end to account for it.
1
1
0
I am preparing to develop a web application that will (hopefully) be used by an audience with many different native languages. What should I do to prepare my software project to have the user interface be almost entirely internationalized? Are there any software stacks that make this easier?
Preparing a web site for international usage
0
0
0
98
3,951,089
2010-10-16T22:29:00.000
0
0
0
1
python,google-app-engine
4,927,348
5
false
1
0
Answer of Adam Bernier also can apply when you use the appcfg.py download_app for downloading app from appengine servers.
1
9
0
I have hosted GAE apps with two different email ids! When i first time used appcfg.py to update my app then it prompted me for email id and password but later it doesnot. How to i change the saved email id and password? I tried to use --email= flag with appcfg.py, but it dint worked.
How to change email account details in appcfg.py google appengine SDK
0
0
0
6,689
3,951,608
2010-10-17T01:36:00.000
1
0
1
0
python,osx-snow-leopard
3,951,616
1
true
0
0
Set the PATH environment variable so that /usr/bin is ahead of wherever you put your custom compiled Python binary.
1
0
0
So earlier this year I manually built 2.6.4 for Snow Leopard because I wanted a slightly more updated version of Python than what Apple released. This has caused all kinds of problems when installing some eggs like PIL and running other 3rd party python apps. Now I just want to revert everything back to what Snow Leopard ships with because I have to get work done and it's getting in the way. If worse comes to worse, I'm going to reinstall the OS but I'd like to avoid that if possible.
How to revert compiled Python 2.6.4 to system default on Snow Leopard?
1.2
0
0
355
3,953,563
2010-10-17T14:07:00.000
2
1
0
0
php,python,xml
3,953,576
3
false
0
0
I think that both of them can rely over wrappers for fast C libraries (mostly libxml2) so there's shouldn't be too much difference in parsing per se. You could try if there are differences caused by overhead, then it depends what are you gonna do over that XML. Parsing it for what?
2
2
0
So I have 16 GB worth of XML files to process (about 700 files total), and I already have a functional PHP script to do that (With XMLReader) but it's taking forever. I was wondering if parsing in Python would be faster (Python being the only other language I'm proficient in, I'm sure something in C would be faster).
Is XML parsing in PHP as fast as Python or other alternatives?
0.132549
0
1
1,714
3,953,563
2010-10-17T14:07:00.000
2
1
0
0
php,python,xml
3,953,874
3
false
0
0
There's actually three differing performance problems here: The time it takes to parse a file, which depends on the size of individual files. The time it takes to handle the files and directories in the filesystem, if there's a lot of them. Writing the data into your databases. Where you should look for performance improvements depends on which one of these is the biggest bottleneck. My guess is that the last one is the biggest problem because writes is almost always the slowest: writes can't be cached, they requires writing to disk and if the data is sorted it can take a considerable time to find the right spot to write it. You presume that the bottleneck is the first alternative, the XML parsing. If that is the case, changing language is not the first thing to do. Instead you should see if there's some sort of SAX parser for your language. SAX parsing is much faster and memory effective than DOM parsing.
2
2
0
So I have 16 GB worth of XML files to process (about 700 files total), and I already have a functional PHP script to do that (With XMLReader) but it's taking forever. I was wondering if parsing in Python would be faster (Python being the only other language I'm proficient in, I'm sure something in C would be faster).
Is XML parsing in PHP as fast as Python or other alternatives?
0.132549
0
1
1,714
3,953,999
2010-10-17T15:56:00.000
0
0
1
0
python,flash,actionscript
3,954,038
4
false
0
0
I am not aware of a browser plug-in for Python. With that in mind, no in-browser games. If you used PyGame you could do network delivered game. Alternately, you could go the AJAXy route and have a Python server work with JavaScript or some other tool a browser. If you go for a hybrid approach pretty much any AJAXy framework would work.
2
3
0
Can python be used as a language to develop browser based games? Like we do in flash. If yes then what frameworks are available to get my hands dirty? If no then what are the reasons?
Python vs Flash
0
0
0
1,390
3,953,999
2010-10-17T15:56:00.000
1
0
1
0
python,flash,actionscript
3,954,129
4
false
0
0
You can run IronPython code in the Silverlight plug-in.
2
3
0
Can python be used as a language to develop browser based games? Like we do in flash. If yes then what frameworks are available to get my hands dirty? If no then what are the reasons?
Python vs Flash
0.049958
0
0
1,390
3,954,099
2010-10-17T16:24:00.000
0
0
0
0
javascript,python,client-side,template-engine
3,954,282
3
false
1
0
I'll address your first question. You can store data in JavaScript objects (instead of SQL databases, for example). Those JavaScript objects can be stored in .js files, or inline as part of the HTML document. You can take a look at the source code of my w3viewer.com. All data is stored inside a JavaScript array. In the example of my web-site, I dynamically create HTML lists with data taken from that JavaScript object (I generate the HTML code string). One could use templating to get this job done.
3
2
0
Recently, I found out that jQuery has an official template engine which was contributed by the Microsoft team. Also I had heard about jTemplate from my friends, but I'm still confused: When & where might I need to use these plugins? How should I choose between the many client side template engines?
When would we need a javascript client template engine?
0
0
0
308
3,954,099
2010-10-17T16:24:00.000
0
0
0
0
javascript,python,client-side,template-engine
3,954,332
3
false
1
0
A template-engine prevents unnecessary HTML-code in the actual code. This makes it much easier to read.
3
2
0
Recently, I found out that jQuery has an official template engine which was contributed by the Microsoft team. Also I had heard about jTemplate from my friends, but I'm still confused: When & where might I need to use these plugins? How should I choose between the many client side template engines?
When would we need a javascript client template engine?
0
0
0
308
3,954,099
2010-10-17T16:24:00.000
1
0
0
0
javascript,python,client-side,template-engine
3,954,142
3
true
1
0
The reason for a jQuery template engine is this: developers write Javascript code to create new chunks of HTML to inject into the page. This usually is done by concatenating many strings with variables for values, and it becomes difficult to maintain. With a jQuery template engine, the process of creating HTML at the client can benefit from all the same advantages that server-side developers now have with their templating engines.
3
2
0
Recently, I found out that jQuery has an official template engine which was contributed by the Microsoft team. Also I had heard about jTemplate from my friends, but I'm still confused: When & where might I need to use these plugins? How should I choose between the many client side template engines?
When would we need a javascript client template engine?
1.2
0
0
308
3,955,077
2010-10-17T20:12:00.000
1
0
0
0
python,image,r,analysis
3,964,945
5
false
0
0
Try the rgdal package. You will be able to read (import) and write (export) GeoTiff image files from/to R. Marcio Pupin Mello
1
15
1
I would like to know how I would go about performing image analysis in R. My goal is to convert images into matrices (pixel-wise information), extract/quantify color, estimate the presence of shapes and compare images based on such metrics/patterns. I am aware of relevant packages available in Python (suggestions relevant to Python are also welcome), but I am looking to accomplish these tasks in R. Thank you for your feedback. -Harsh
Image analysis in R
0.039979
0
0
4,953
3,955,361
2010-10-17T21:22:00.000
2
0
0
1
python,django,google-app-engine
3,957,752
2
true
1
0
os.path.normpath() on "content_includes" is a no-op - normpath just removes double slashes and other denormalizations. What you probably want is to build a path relative to the script, in which case you should do something like os.path.join(os.path.dirname(__file__), 'content_includes', pageName + '.inc').
2
2
0
I created a simple python project that serves up a couple of pages. I'm using the 'webapp' framework and django. What I'm trying to do is use one template file, and load 'content files' that contain the actual page text. When I try to read the content files using os.open, I get the following error: pageContent = os.open(pageUrl, 'r').read() OSError: [Errno 1] Operation not permitted: 'content_includes/home.inc' error If I let the django templating system to read the same file for me, everything works fine! So the question is What am I doing wrong that django isn't??? The same 'pageUrl' is used. The code below will give me the error, while if I comment out the first pageContent assignment, everything works fine. Code: pageName = "home"; pageUrl = os.path.join(os.path.normpath('content_includes'), pageName + '.inc') pageContent = os.open(pageUrl, 'r').read() pageContent=template.render(pageUrl, template_values, debug=True); template_values = { 'page': pageContent, 'test': "testing my app" } Error: Traceback (most recent call last): File "/opt/apis/google_appengine/google/appengine/ext/webapp/__init__.py", line 511, in __call__ handler.get(*groups) File "/home/odessit/Development/Python/Alpha/main.py", line 19, in get pageContent = os.open(pageUrl, 'r').read() File "/opt/apis/google_appengine/google/appengine/tools/dev_appserver.py", line 805, in FakeOpen raise OSError(errno.EPERM, "Operation not permitted", filename) OSError: [Errno 1] Operation not permitted: 'content_includes/home.inc' app.yaml: handlers: - url: /javascript static_dir: javascript - url: /images static_dir: images - url: /portfolio static_dir: portfolio - url: /.* script: main.py
Reading files in GAE using python
1.2
0
0
613
3,955,361
2010-10-17T21:22:00.000
0
0
0
1
python,django,google-app-engine
3,994,580
2
false
1
0
If you dig in the dev_appserver.py source code and related files you see that the server does some incarnate checking to ensure that you open only files from below your applications root (in fact the rules seem even more complex). For file access troubled I instrumented that "path permission checking" code from the development server to find that I was using absolute paths. We propbably should do a patch to appengine to provide better error reporting on that: IIRC the Appserver does not display the offending path but a mangled version of this which makes debugging difficult.
2
2
0
I created a simple python project that serves up a couple of pages. I'm using the 'webapp' framework and django. What I'm trying to do is use one template file, and load 'content files' that contain the actual page text. When I try to read the content files using os.open, I get the following error: pageContent = os.open(pageUrl, 'r').read() OSError: [Errno 1] Operation not permitted: 'content_includes/home.inc' error If I let the django templating system to read the same file for me, everything works fine! So the question is What am I doing wrong that django isn't??? The same 'pageUrl' is used. The code below will give me the error, while if I comment out the first pageContent assignment, everything works fine. Code: pageName = "home"; pageUrl = os.path.join(os.path.normpath('content_includes'), pageName + '.inc') pageContent = os.open(pageUrl, 'r').read() pageContent=template.render(pageUrl, template_values, debug=True); template_values = { 'page': pageContent, 'test': "testing my app" } Error: Traceback (most recent call last): File "/opt/apis/google_appengine/google/appengine/ext/webapp/__init__.py", line 511, in __call__ handler.get(*groups) File "/home/odessit/Development/Python/Alpha/main.py", line 19, in get pageContent = os.open(pageUrl, 'r').read() File "/opt/apis/google_appengine/google/appengine/tools/dev_appserver.py", line 805, in FakeOpen raise OSError(errno.EPERM, "Operation not permitted", filename) OSError: [Errno 1] Operation not permitted: 'content_includes/home.inc' app.yaml: handlers: - url: /javascript static_dir: javascript - url: /images static_dir: images - url: /portfolio static_dir: portfolio - url: /.* script: main.py
Reading files in GAE using python
0
0
0
613
3,955,903
2010-10-18T00:17:00.000
5
0
1
0
python,pep8,pep
33,581,024
14
false
0
0
The "problem" with PEP 8 is that it treads on areas of personal preference that are subject to quite high amounts of emotion for most programmers. For me personally, camelCase vs underscores and column alignment directives were constant issues. I also see point in lots of other responses here and sometimes I break PEP 8 intentionally because in that particular case it just "makes sense". There was a point in my Python programming career when I simply gave up and turned to (using) PEP 8. It was relatively easy for most items, so nowadays the only major issue I still have is the column alignment. That one's just too messy to obey(though I hatefully do anyway). Anyway, as a result of my "giving up", my code is now much more readable to my colleagues - and - surprisingly: even to me (except for the column alignment thingy :p ). I must also recognize what PEP 8 has done for python itself: between 2.x (non-compliant) and 3.x (compliant), I find it much easier to "always know" what a particular function's name will be. Python's "batteries" are sorted much nicer now.
2
46
0
Over the years, the more Python I write, the more I find myself agreeing with most of the guidelines, though I consistently and intentionally break some for my own reasons. I'd be curious to know what in PEP 8 (or other PEPs too maybe) people religiously stick to and why, and what people find inconvenient or inadequate. In my case (and at work in general), there's only a handful of things we deviate from: Underscore separated lowercase names, I can see the point of it, as it will unfailingly be consistent, but we tend to use lowerCamelCase, even if it will occasionally introduce some inconsistencies (such as partially or mis-capitalized acronyms and following words, which are often down to spur-of-the-moment calls). Mostly because the near totality of the APIs we routinely use use camelCase (some upper, some lower), and because for some reason I find it easier to read, and tend to reserve underscores as separation tokens or prescribed mangling/obscuring. I still can't get myself to space things out the way the PEP prescribes inside objects. new and init I tend to leave right under the class with no blank lines as I always want to read them right there with the class name and args, methods that contribute to the same scope of functionality in the class (say init, get and set of the same attrib or set of attribs) I only single-space apart, and I like three spaces between classes, and two between methods I wouldn't mentally aggregate in the map of that object. This is, again, purely for the visual impact and readability of the code. I find that very compact contents inside flow control and this kind of spacing between methods and objects consistently leads my eye exactly where I want it to go on re-readings months after the code had been parked. It also responds well to folding in my editors of choice. Some things instead I stick to, that drive me nuts when I read otherwise written, is tabs instead of spaces (especially when some in-app editors we use don't really have tab replacement functionalities, contributing considerably to pollution in the code base at prototyping stage). Order of things such as imports, and what imports, globals etc. It really throws me off on files that have large amounts of imports when those are mixed up or out of order. Whitespaces in statements, especially when people use tabs AND try to align assignment ops across lines with different length in var names (and there seems to be no way to persuade those who do it that an excel looking piece of code is NOT neater ;) ). And spacing within a control block, particularly when I see apparently random spacing within the same flow control block, and then similar amounts of spacing used within the object for methods. I'm compelled to edit those before I can even start reading the damn thing. So, those are mine, and the reasoning behind my "violations" of the PEP (some shared, some frowned upon by colleagues). I'd be very curious to read what other Pythonistas do and don't do in those regards.
What PEP 8 guidelines do you ignore, and which ones do you stick to?
0.071307
0
0
21,397
3,955,903
2010-10-18T00:17:00.000
11
0
1
0
python,pep8,pep
23,239,799
14
false
0
0
My company's style guidelines specifically call for tabs, not spaces. PEP 8 hints that spaces are preferable but we've found the opposite. I like to see code indented 4 'spaces' in VIM, a coworker prefers 8 'spaces' in Emacs. Using tabs lets us both set our editors to show the code as we prefer it. Note that in other C-based languages, indentation is in fact merely formatting but in Python indentation is syntax, thus we feel that indentation level 2 should be represented by 2 of something (i.e. tabs) not 4 or 8 of something (i.e. spaces). Indentation character selection is probably the original holy flame war (even before the VIM / Emacs flamewars) so I do expected to be modded to oblivion for expressing an opinion on the subject!
2
46
0
Over the years, the more Python I write, the more I find myself agreeing with most of the guidelines, though I consistently and intentionally break some for my own reasons. I'd be curious to know what in PEP 8 (or other PEPs too maybe) people religiously stick to and why, and what people find inconvenient or inadequate. In my case (and at work in general), there's only a handful of things we deviate from: Underscore separated lowercase names, I can see the point of it, as it will unfailingly be consistent, but we tend to use lowerCamelCase, even if it will occasionally introduce some inconsistencies (such as partially or mis-capitalized acronyms and following words, which are often down to spur-of-the-moment calls). Mostly because the near totality of the APIs we routinely use use camelCase (some upper, some lower), and because for some reason I find it easier to read, and tend to reserve underscores as separation tokens or prescribed mangling/obscuring. I still can't get myself to space things out the way the PEP prescribes inside objects. new and init I tend to leave right under the class with no blank lines as I always want to read them right there with the class name and args, methods that contribute to the same scope of functionality in the class (say init, get and set of the same attrib or set of attribs) I only single-space apart, and I like three spaces between classes, and two between methods I wouldn't mentally aggregate in the map of that object. This is, again, purely for the visual impact and readability of the code. I find that very compact contents inside flow control and this kind of spacing between methods and objects consistently leads my eye exactly where I want it to go on re-readings months after the code had been parked. It also responds well to folding in my editors of choice. Some things instead I stick to, that drive me nuts when I read otherwise written, is tabs instead of spaces (especially when some in-app editors we use don't really have tab replacement functionalities, contributing considerably to pollution in the code base at prototyping stage). Order of things such as imports, and what imports, globals etc. It really throws me off on files that have large amounts of imports when those are mixed up or out of order. Whitespaces in statements, especially when people use tabs AND try to align assignment ops across lines with different length in var names (and there seems to be no way to persuade those who do it that an excel looking piece of code is NOT neater ;) ). And spacing within a control block, particularly when I see apparently random spacing within the same flow control block, and then similar amounts of spacing used within the object for methods. I'm compelled to edit those before I can even start reading the damn thing. So, those are mine, and the reasoning behind my "violations" of the PEP (some shared, some frowned upon by colleagues). I'd be very curious to read what other Pythonistas do and don't do in those regards.
What PEP 8 guidelines do you ignore, and which ones do you stick to?
1
0
0
21,397
3,957,025
2010-10-18T06:38:00.000
6
1
1
0
python,wav
9,184,327
4
false
1
0
The first thing you should do is a fourier transformation to transform the data into its frequencies. It is rather complex however. I wouldn't use voice recognition libraries here as it sounds like you don't record voices only. You would then try different time shifts (in case the sounds are not exactly aligned) and use the one that gives you the best similarity - where you have to define a similarity function. Oh and you should normalize both signals (same maximum loudness).
4
23
0
I'm doing some research on how to compare sound files(wave). Basically, I want to compare stored soundfiles (wav) with sound from a microphone. So in the end I would like to pre-store some voice commands of my own and then when I'm running my app I would like to compare the pre-stored files with input from the microphone. My thought was to put in some margin when comparing because saying something two times in a row in the exactly same way would be difficult I guess. So after some googling I see that Python has this module named wave and the Wave_read object. That object has a function named readframes(n): Reads and returns at most n frames of audio, as a string of bytes. What do these bytes contain? I'm thinking of looping thru the wave files one frame at the time comparing them frame by frame.
What does a audio frame contain?
1
0
0
39,854
3,957,025
2010-10-18T06:38:00.000
7
1
1
0
python,wav
20,810,191
4
false
1
0
I believe the accepted description to be slightly incorrect. A frame appears to be somewhat like stride in graphics formats. For interleaved stereo @ 16 bits/sample, the frame size is 2*sizeof(short)=4 bytes. For non-interleaved stereo @ 16 bits/sample, the samples of the left channel are all one after another, so the frame size is just sizeof(short).
4
23
0
I'm doing some research on how to compare sound files(wave). Basically, I want to compare stored soundfiles (wav) with sound from a microphone. So in the end I would like to pre-store some voice commands of my own and then when I'm running my app I would like to compare the pre-stored files with input from the microphone. My thought was to put in some margin when comparing because saying something two times in a row in the exactly same way would be difficult I guess. So after some googling I see that Python has this module named wave and the Wave_read object. That object has a function named readframes(n): Reads and returns at most n frames of audio, as a string of bytes. What do these bytes contain? I'm thinking of looping thru the wave files one frame at the time comparing them frame by frame.
What does a audio frame contain?
1
0
0
39,854
3,957,025
2010-10-18T06:38:00.000
8
1
1
0
python,wav
3,957,097
4
false
1
0
A simple byte-by-byte comparison has almost no chance of a successful match, even with some tolerance thrown in. Voice-pattern recognition is a very complex and subtle problem that is still the subject of much research.
4
23
0
I'm doing some research on how to compare sound files(wave). Basically, I want to compare stored soundfiles (wav) with sound from a microphone. So in the end I would like to pre-store some voice commands of my own and then when I'm running my app I would like to compare the pre-stored files with input from the microphone. My thought was to put in some margin when comparing because saying something two times in a row in the exactly same way would be difficult I guess. So after some googling I see that Python has this module named wave and the Wave_read object. That object has a function named readframes(n): Reads and returns at most n frames of audio, as a string of bytes. What do these bytes contain? I'm thinking of looping thru the wave files one frame at the time comparing them frame by frame.
What does a audio frame contain?
1
0
0
39,854
3,957,025
2010-10-18T06:38:00.000
47
1
1
0
python,wav
3,957,230
4
true
1
0
An audio frame, or sample, contains amplitude (loudness) information at that particular point in time. To produce sound, tens of thousands of frames are played in sequence to produce frequencies. In the case of CD quality audio or uncompressed wave audio, there are around 44,100 frames/samples per second. Each of those frames contains 16-bits of resolution, allowing for fairly precise representations of the sound levels. Also, because CD audio is stereo, there is actually twice as much information, 16-bits for the left channel, 16-bits for the right. When you use the sound module in python to get a frame, it will be returned as a series of hexadecimal characters: One character for an 8-bit mono signal. Two characters for 8-bit stereo. Two characters for 16-bit mono. Four characters for 16-bit stereo. In order to convert and compare these values you'll have to first use the python wave module's functions to check the bit depth and number of channels. Otherwise, you'll be comparing mismatched quality settings.
4
23
0
I'm doing some research on how to compare sound files(wave). Basically, I want to compare stored soundfiles (wav) with sound from a microphone. So in the end I would like to pre-store some voice commands of my own and then when I'm running my app I would like to compare the pre-stored files with input from the microphone. My thought was to put in some margin when comparing because saying something two times in a row in the exactly same way would be difficult I guess. So after some googling I see that Python has this module named wave and the Wave_read object. That object has a function named readframes(n): Reads and returns at most n frames of audio, as a string of bytes. What do these bytes contain? I'm thinking of looping thru the wave files one frame at the time comparing them frame by frame.
What does a audio frame contain?
1.2
0
0
39,854
3,957,938
2010-10-18T09:36:00.000
1
0
0
0
python,sqlalchemy,python-elixir
3,975,114
3
false
0
0
The Elixir syntax is something I find useful when building a database for a given app from scratch and everything is all figured out beforehand. I have had my best luck with SQLAlchemy when using it on legacy databases (and on other similarly logistically immutable schemas). Particularly useful is the plugin SQLSoup, for read-only one-time extractions of data in preparation for migrating it elsewhere. YMMV but Elixir isn't really designed to adapt to older schemas -- and SQLAlchemy proper is overkill for most small- to mid-size projects (in my opinion of course).
1
7
0
... vs declarative sqlalchemy ?
What are the benefits of using Elixir
0.066568
1
0
4,024
3,958,019
2010-10-18T09:48:00.000
1
1
0
0
python,gmail,imaplib
3,984,960
2
true
0
0
You can do it using any of the 2 following ways. You can use Message-Id field of the mail header.Message-Id field for both the mail will be same. Apply SEARCH command on All Mail Folder. i.e search on title --> it will give you uid for that mail.
1
2
0
How to get UID of mail in All Maill folder if I have UID of this mail in inbox using imaplib? As you know the google store mails in the two instances in All Mail and in inbox I whant to move this to mail in trash folder using imaplib
How to get UID of mail in All Maill folder if I have UID of this mail in inbox using imaplib? (GMail)
1.2
0
0
2,438
3,958,044
2010-10-18T09:53:00.000
3
0
0
1
python,linux,ubuntu,debian
3,958,070
3
false
0
0
Closed-source? Meh. Well, you can compile python iirc, or simply use an obscusificator. But I recommend to open-source it ;-) The stuff you can double-click are .desktop files, for samples, see find /usr | grep desktop.
1
2
0
I have created a simple program in python. Now I want trasform this script in an executable program ( with hidden source code if possible ) and when I click 2 times on it, the program install itself on the ubuntu ( in the /usr/lib or /usr/bin I think ) and it will create a new launcher in the Application -> Game menu. How can I do that ?
How create an Executable file + Launcher in Ubuntu from a python script?
0.197375
0
0
7,715
3,958,224
2010-10-18T10:24:00.000
1
0
0
1
python,google-app-engine
3,959,150
2
false
1
0
Afaik you can not store files in App Engine programmatically. You can just store them, when uploading your app. You can however store information in its data store. So you would need to deploy an app, that authenticates your user and then writs the image to the gae's data store
1
1
0
I am not running Django on AppEngine. I just want to use AppEngine as a content delivery network, basically a place I can host and serve images for free. It's for a personal side project. The situation is this: I have the URL of an image hosted on another server/provider. Instead of hotlinking to that image its better to save it on AppEngine and serve it from there - this applies mostly for thumbnails. My questions are these: How do I authenticate from my Django app (let's say A) to my AppEngine app (B), so that only I can upload images How do I make a request from A to B saying "Fetch the image on this URL, create a thumbnail and save it." How do I tell B that "For this url return that image" How can I handle errors or timeouts? And how can this be done asynchronously?
Uploading images from a django application to a Google AppEngine application
0.099668
0
0
269
3,958,772
2010-10-18T11:46:00.000
1
0
0
0
c#,java,python,opengl,3d
3,960,791
3
false
0
0
The easiest way would be to use PANDA3D. it uses python and is quite complete.
2
1
0
I am building a ship simulator that will produce accurate position and orientation values for a prototype hull design in some defined sea-state. In terms of programming, I have 2 arrays (vectors) in MATLAB containing the position and acceleration values for x, y, z, yaw, pitch and roll. Because the visualisations in MATLAB are a bit crude, I am planning to write a simple server within MATLAB to send these values (at 200Hz) using sockets to another program. The sea is modelled as an array of vertices (think of amplitude snapshots at different timesteps on a sine wave). So my question is, what's the easiest way to animate a 3D boat and some textured water on screen? I am only interested in the graphics engine. I have no need for sound, physics, collisions, interface (keyboard, joystick, etc). It should be able to run primarily on Windows, but it would be nice if it could run on Linux and Mac OS too (depending on the additional complexity involved).
easiest way to make a live 3d scene, a bit like a simple game (for simulator visualisation purposes)
0.066568
0
0
587
3,958,772
2010-10-18T11:46:00.000
0
0
0
0
c#,java,python,opengl,3d
3,958,801
3
false
0
0
I've found OpenGL pretty easy to use in the past, or if you're on a Windows environment there's Direct3D too.
2
1
0
I am building a ship simulator that will produce accurate position and orientation values for a prototype hull design in some defined sea-state. In terms of programming, I have 2 arrays (vectors) in MATLAB containing the position and acceleration values for x, y, z, yaw, pitch and roll. Because the visualisations in MATLAB are a bit crude, I am planning to write a simple server within MATLAB to send these values (at 200Hz) using sockets to another program. The sea is modelled as an array of vertices (think of amplitude snapshots at different timesteps on a sine wave). So my question is, what's the easiest way to animate a 3D boat and some textured water on screen? I am only interested in the graphics engine. I have no need for sound, physics, collisions, interface (keyboard, joystick, etc). It should be able to run primarily on Windows, but it would be nice if it could run on Linux and Mac OS too (depending on the additional complexity involved).
easiest way to make a live 3d scene, a bit like a simple game (for simulator visualisation purposes)
0
0
0
587
3,961,945
2010-10-18T17:58:00.000
0
0
1
0
python,urllib2
3,962,002
2
false
0
0
Req refers to request object usually contains HTTP method and url code refers to response code or HTTP code value like 200 etc hdr refers to headers of the request like user-agent etc fp refers to file descriptor or socket descriptor in this case
1
1
0
In the method of the class urllib2.HTTPDefaultErrorHandler what so the arguments - self, req, fp, code,msg, hdrs - refer to?
What do these arguments refer to?
0
0
0
72
3,962,304
2010-10-18T18:46:00.000
0
0
0
0
python,django,gps
3,962,335
2
true
1
0
Save them as double/float with adequate precision in the input data
1
1
0
What is the best way to manage GPS coordinates (latitude and longitude) in django models ? I know that there is a module called GeoDjango but reading the tutorial seems dedicated to GIS and not simply to manage the latitude and longitude. I do not care to have convenient interface for the admin because int the application I'm creatin the admin is virtually absent. But instead the application will often comunicate with mobile device such as iPhone that,for example, treat coordinates as double (double typedef CLLocationDegrees). I would simply like an easy way to manage these data in the model?
Handle GPS Coordinate in Django
1.2
0
0
1,957
3,963,438
2010-10-18T21:12:00.000
0
1
1
0
python,programming-languages
3,963,524
6
false
0
0
The stock answer is the only features that make certain languages more powerful than others are language features that cannot be easily replaced by adding libraries. This definition will almost always list LISP on the top, but has the odd side effect of listing assembly near the top unless special care is taken to exclude it.
4
5
0
I'm going to reveal my ignorance here, but in my defense, I'm an accounting major, and I've never taken a computer science class. I'm about to start a new project, and I'm considering using Python instead of PHP, even though I am much more adept with PHP, because I have heard that Python is a more powerful language. That got me wondering, what makes one programming language more powerful than another? I figure javascript isn't very powerful because it (generally) runs inside a browser. But, why is Python more powerful than PHP? In each case, I'm giving instructions to the computer, so why are some languages better at interpreting and executing these instructions? How do I know how much "power" I actually need for a specific project?
What makes some programming languages more powerful than others?
0
0
0
6,357
3,963,438
2010-10-18T21:12:00.000
1
1
1
0
python,programming-languages
3,963,547
6
false
0
0
I would not say that there are computer languages "more powerful", just languages more suited for your specific problem domain. That said, PHP is a language that evolved from a hack and tailored for a very specific problem domain; this shows up in several places, like for example inconsistent parameter order across database interfaces. IMHO PHP community has made some very sad decisions for new syntax enhancements over the time. IMHO Python is much more general, well designed and elegant, but your question is one that usually starts flamewars.
4
5
0
I'm going to reveal my ignorance here, but in my defense, I'm an accounting major, and I've never taken a computer science class. I'm about to start a new project, and I'm considering using Python instead of PHP, even though I am much more adept with PHP, because I have heard that Python is a more powerful language. That got me wondering, what makes one programming language more powerful than another? I figure javascript isn't very powerful because it (generally) runs inside a browser. But, why is Python more powerful than PHP? In each case, I'm giving instructions to the computer, so why are some languages better at interpreting and executing these instructions? How do I know how much "power" I actually need for a specific project?
What makes some programming languages more powerful than others?
0.033321
0
0
6,357
3,963,438
2010-10-18T21:12:00.000
0
1
1
0
python,programming-languages
3,963,564
6
false
0
0
Its an interesting topic and in my line of word I come across this a lot. But I've discovered 'power' in the literal sense no longer has value when it comes to the language. What I fear those telling you 'python is more' powerful are getting mixed up with the language and the implementation. I'm a recent convert to python (last 2 weeks) previously I was a PHP coder. The libraries made on top of the language of python - namely django -help make the language more powerful - as its faster to use and build upon. PHP has the fable 'if you want to do something. there is a function for it' and the documentation is brilliant - therefore powerful in that sense. And in regards to interpreting the language - again dependant upon who has been coding it - its no matter. By general consensus python may be considered quicker and less CPU intensive, is it creates compiled versions of your code. But PHP can have a good caching system. In short - Pick you favorite.
4
5
0
I'm going to reveal my ignorance here, but in my defense, I'm an accounting major, and I've never taken a computer science class. I'm about to start a new project, and I'm considering using Python instead of PHP, even though I am much more adept with PHP, because I have heard that Python is a more powerful language. That got me wondering, what makes one programming language more powerful than another? I figure javascript isn't very powerful because it (generally) runs inside a browser. But, why is Python more powerful than PHP? In each case, I'm giving instructions to the computer, so why are some languages better at interpreting and executing these instructions? How do I know how much "power" I actually need for a specific project?
What makes some programming languages more powerful than others?
0
0
0
6,357