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
2,059,337
2010-01-13T18:52:00.000
0
1
0
1
python,ruby,linux,scripting,release
4,454,448
4
false
1
0
One downside of doing an svn update: though you can go back in time, to what revision do you go back to? You have to look it up. svn update pseudo-deployments work much cleaner if you use tags - in that case you'd be doing an svn switch to a different tag, not an svn update on the same branch or the trunk. You want to tag your software with the version number something like 1.1.4 , and then have a simple script to zip it up application-1.1.4,zip, and deploy it - then you have automated repeatable releases and rollbacks as well as greater visibility into what is changing between releases.
3
1
0
I am purely a windows programmer and spend all my time hacking VC++. Recently I have been heading several web based applications and myself built applications with python (/pylons framework) and doing projects on rails. All the web projects are hosted on ubuntu linux. The RELEASE procedures and check list we followed for building and releasing VC++ windows application are merely no more useful when it comes to script based language. So we don't built any binaries now. I copied asp/php files into IIS folder through ftp server when using open source cms applications. So FTP is the one of the way to host the files to the web server. Now we feel lazy or not so passionate to copy files via ftp instead we use the SVN checkout and we simply do svn update to get the latest copy. Is SVN checkout and svn update are the right methods to update the latest build files into the server? Are there any downside in using svn update? Any better method to release the script/web based scripts into the production server? PS: I have used ssh server at some extension on linux platform.
Practices while releasing the python/ruby/script based web applications on production
0
0
0
242
2,059,337
2010-01-13T18:52:00.000
2
1
0
1
python,ruby,linux,scripting,release
2,059,406
4
false
1
0
Is SVN checkout and svn update are the right methods to update the latest build files into the server? Very, very good methods. You know what you got. You can go backwards at any time. Are there any downside in using svn update? None. Any better method to release the script/web based scripts into the production server? What we do. We do not run out of the SVN checkout directories. The SVN checkout directory is "raw" source sitting on the server. We use Python's setup.py install to create the application in /opt/app/app-x.y directory tree. Each tagged SVN branch is also a branch in the final installation. Ruby has gems and other installation tools that are probably similar to Python's. Our web site's Apache and mod_wsgi configurations refer to a specific /opt/app/app-x.y version. We can then stage a version, do testing, do things like migrate data from production to the next release, and generally get ready. Then we adjust our Apache and mod_wsgi configuration to use the next version. Previous versions are all in place. And left in place. We'll delete them some day when they confuse us.
3
1
0
I am purely a windows programmer and spend all my time hacking VC++. Recently I have been heading several web based applications and myself built applications with python (/pylons framework) and doing projects on rails. All the web projects are hosted on ubuntu linux. The RELEASE procedures and check list we followed for building and releasing VC++ windows application are merely no more useful when it comes to script based language. So we don't built any binaries now. I copied asp/php files into IIS folder through ftp server when using open source cms applications. So FTP is the one of the way to host the files to the web server. Now we feel lazy or not so passionate to copy files via ftp instead we use the SVN checkout and we simply do svn update to get the latest copy. Is SVN checkout and svn update are the right methods to update the latest build files into the server? Are there any downside in using svn update? Any better method to release the script/web based scripts into the production server? PS: I have used ssh server at some extension on linux platform.
Practices while releasing the python/ruby/script based web applications on production
0.099668
0
0
242
2,059,455
2010-01-13T19:07:00.000
0
0
0
0
python,xml,sax
2,059,524
1
true
0
0
Expat can be stopped and is resumable. AFAIK Python SAX parser uses Expat. Does the API really not expose the stopping stuff to the Python side?? EDIT: nope, looks like the parser stopping isn't available from Python...
1
1
0
I am pretty sure the answer is no but of course there are cleverer guys than me! Is there a way to construct a lazy SAX based XML parser that can be stopped (e.g. raising an exception is a possible way of doing this) but also resumable ? I am looking for a possible solution for Python >= 2.6 with standard XML libraries. The "lazy" part is also trivial: I am really after the "resumable" property here.
Lazy SAX XML parser with stop/resume
1.2
0
1
1,020
2,059,685
2010-01-13T19:43:00.000
1
0
1
0
python,c,ipc
2,059,797
2
true
0
0
You can certainly use the C API to do what you want. You'll create a class in C, which can hold onto any memory it wants. That memory doesn't have to be exposed to Python at all if you don't want. If you are comfortable building C DLLs, and don't need to perform Python operations in C, then ctypes might be your best bet.
1
2
0
I'm considering integrating some C code into a Python system (Django), and I was considering using the Python / C API. The alternative is two separate processes with IPC, but I'm looking into direct interaction first. I'm new to Python so I'm trying to get a feel for the right direction to take. Is it possible for a call to a C initialiser function to malloc a block of memory (and put something in it) and return a handle to it back to the Python script (pointer to the start of the memory block). The allocated memory should remain on the heap after the init function returns. The Python script can then call subsequent C functions (passing as an argument the pointer to the start of memory) and the function can do some thinking and return a value to the Python script. Finally, there's another C function to deallocate the memory. Assume that the application is single-threaded and that after the init function, the memory is only read from so concurrency isn't an issue. The amount of memory will be a few hundred megabytes. Is this even possible? Will Python let me malloc from the heap and allow it to stay there? Will it come from the Python process's memory? Will Python try and clear it up (i.e. does it do its own memory allocation and not expect any other processes to interfere with its address space)? Could I just return the byte array as a Python managed string (or similar datatype) and pass the reference back as an argument to the C call? Would Python be OK with such a large string? Would I be better off doing this with a separate process and IPC?
Python C API and data persistent in memory?
1.2
0
0
406
2,060,341
2010-01-13T21:16:00.000
1
0
0
0
python,design-patterns,oop
2,060,509
6
false
1
0
For web applications, understanding at least at a rudimentary level the patterns described in Patterns of Enterprise Application Architecture has proven valuable to me. Gang of Four patterns are worth knowing, too. But I would argue that you simply don't need encyclopedic knowledge of patterns to get started. A cursory understanding will help you understand where to look when you start to encounter friction between your ideas/business problems and your code. I had a couple of weekend trips that allowed me to plow through these two books in their entirety, but I still find the detailed information in the patterns section more useful as a reference than as background knowledge. Reading just the "Part 1" sections of the GoF or PoEAA will help you far more than learning three or four patterns in depth, because you'll know where to look when you encounter problems they describe. And you can look up the details of most of the patterns they describe online. GoF patterns that I use directly or indirectly, often unconsciously, in web development, include: Observer, Command, Composite, State, Strategy. I usually don't use Singleton except as a client of logging and service locator/dependency injection tools. PoEAA patterns that I use regularly, usually unconsciously, or incidentally as a part of the data access strategy or web framework I'm using, are Active Record, Application Controller, Data Mapper, Domain Model, Gateway, Lazy Load, Layer Supertype, Page Controller, Template View, and Value Object. That's not exhaustive; these are just a few that popped into mind. Most of those are probably more usefully learned by starting with an opinionated web development framework, like Rails, Django, or Castle Monorail, than in the abstract. After all, patterns were identified and extracted from thousands of successful app development experiences, not invented and then glued on because they sounded clever. It's pretty easy to get overly excited by better-than-superficial knowledge gained on one or two patterns and then seeing "only nails" for every problem you see shortly thereafter and trying to hammer an ill-fitting pattern into a solution because you understand how it works. So, learn patterns, yes; get a superficial overview of the motivations of all of the commonly used ones, but don't feel like you have to wait to write serious code until you understand some arbitrary list of them.
5
5
0
What are the design patterns that I should be completely familiar with? And what is one easy example that each can be used for? I am a web developer (I use Django, and is familiar with separation of logic), but I work at a Desktop-app company. They are always talking about singletons, and I forget...but it leaves me no clue!
How important are design patterns in web development?
0.033321
0
0
1,248
2,060,341
2010-01-13T21:16:00.000
1
0
0
0
python,design-patterns,oop
2,060,471
6
false
1
0
Knowing design patterns won't be much use until you know why they are the best strategy for a given problem. Learning design patterns from the very beginning is probably fine, except you've missed all the "wrong" ways to solve that problem, which in turn means you may be missing subtle difference in when to use the given pattern and when to not use it. The only thing worse than people who stick to their old ways and don't bother learning the proper way, is people who learn the proper way and don't bother learning why that way is proper. And they keep applying it to stuff that it shouldn't be applied to, because they just don't know better. So my point is, if you're new at web development, don't be too caught up in the design pattern hype (though it's a good hype). Learn by doing stuff yourself. When you've reached a certain level, read up on design patterns and see where they could have been applied to have made your code better. THAT is how you learn them properly. Not like being forced to run before you can walk.
5
5
0
What are the design patterns that I should be completely familiar with? And what is one easy example that each can be used for? I am a web developer (I use Django, and is familiar with separation of logic), but I work at a Desktop-app company. They are always talking about singletons, and I forget...but it leaves me no clue!
How important are design patterns in web development?
0.033321
0
0
1,248
2,060,341
2010-01-13T21:16:00.000
0
0
0
0
python,design-patterns,oop
2,060,411
6
false
1
0
MVVM is a newer one I have seen used with Silverlight. It's a bit much, but it seems effective.
5
5
0
What are the design patterns that I should be completely familiar with? And what is one easy example that each can be used for? I am a web developer (I use Django, and is familiar with separation of logic), but I work at a Desktop-app company. They are always talking about singletons, and I forget...but it leaves me no clue!
How important are design patterns in web development?
0
0
0
1,248
2,060,341
2010-01-13T21:16:00.000
2
0
0
0
python,design-patterns,oop
2,060,409
6
false
1
0
Honestly, patterns are important but knowing when to use them is just as important. There is never going to be any set answer it is something you need to feel out for yourself. People that fight about it being an absolute where you should always use them or always not use them are incorrect. Design patterns are a tool. I would suggest looking at Amazon.com for a book in whatever language you are writing in that deals specifically with design patterns. I know there is one written for Ruby on Rails that is great though I don't remember the name, there is also one for Java called Head First Design Patterns, and on for C# written by Bob and Micah Martin that is excellent. Read whichever one of those that applies to the language you are most familiar with. Even if you don't use all of the patterns it is good to understand how they work and when they will be useful to use.
5
5
0
What are the design patterns that I should be completely familiar with? And what is one easy example that each can be used for? I am a web developer (I use Django, and is familiar with separation of logic), but I work at a Desktop-app company. They are always talking about singletons, and I forget...but it leaves me no clue!
How important are design patterns in web development?
0.066568
0
0
1,248
2,060,341
2010-01-13T21:16:00.000
10
0
0
0
python,design-patterns,oop
2,060,384
6
true
1
0
Forget Singleton. It's confusing and rarely necessary. Learn State, Strategy and Command. They're used all the time. State is for anything that has logic that depends on the state of the object. In short, every if-statement might possibly be better done via State. Seriously. Too many if-statements are a code smell and indicate that there's stateful processing that's sprawled all over the place. Strategy is for any "plug-in" or "expansion" or "option" processing. Command is for any extensible (and composable) set of actions. Backup, Restore. Table Drop, Create, Index, Populate. Validate, Load, Summarize, Report. Any of those command-like things that can be put together in different ways, different orders, etc., should probably be done with a formal Command design.
5
5
0
What are the design patterns that I should be completely familiar with? And what is one easy example that each can be used for? I am a web developer (I use Django, and is familiar with separation of logic), but I work at a Desktop-app company. They are always talking about singletons, and I forget...but it leaves me no clue!
How important are design patterns in web development?
1.2
0
0
1,248
2,061,222
2010-01-13T23:53:00.000
1
0
1
0
python,data-structures,hash,dictionary,hashtable
2,061,323
7
false
0
0
A hash table always uses some function operating on a value to determine where a value will be stored. A Dictionary (as I believe you intend it) is a more general term, and simply indicates a lookup mechanism, which might be a hash table or might be implemented by a simpler structure which does not consider the value itself in determining its storage location.
4
62
0
I've always used dictionaries. I write in Python.
What is the true difference between a dictionary and a hash table?
0.028564
0
0
56,356
2,061,222
2010-01-13T23:53:00.000
12
0
1
0
python,data-structures,hash,dictionary,hashtable
2,061,236
7
false
0
0
A Python dictionary is internally implemented with a hashtable.
4
62
0
I've always used dictionaries. I write in Python.
What is the true difference between a dictionary and a hash table?
1
0
0
56,356
2,061,222
2010-01-13T23:53:00.000
36
0
1
0
python,data-structures,hash,dictionary,hashtable
2,061,248
7
false
0
0
A dictionary is a data structure that maps keys to values. A hash table is a data structure that maps keys to values by taking the hash value of the key (by applying some hash function to it) and mapping that to a bucket where one or more values are stored. IMO this is analogous to asking the difference between a list and a linked list. For clarity it may be important to note that it MAY be the case that Python currently implements their dictionaries using hash tables, and it MAY be the case in the future that Python changes that fact without causing their dictionaries to stop being dictionaries.
4
62
0
I've always used dictionaries. I write in Python.
What is the true difference between a dictionary and a hash table?
1
0
0
56,356
2,061,222
2010-01-13T23:53:00.000
0
0
1
0
python,data-structures,hash,dictionary,hashtable
2,061,300
7
false
0
0
Dictionary is implemented using hash tables. In my opinion the difference between the 2 can be thought of as the difference between Stacks and Arrays where we would be using arrays to implement Stacks.
4
62
0
I've always used dictionaries. I write in Python.
What is the true difference between a dictionary and a hash table?
0
0
0
56,356
2,064,202
2010-01-14T13:06:00.000
2
0
1
0
python,class,oop,member-variables
42,183,627
9
false
0
0
This is kinda a l-o-n-g answer but I think it gets to the root of the real problem here -- scope of visibility. Just hang in there while I slog through this! Simply importing a module need not necessarily give the application developer access to all of its classes or methods; if I can't actually SEE the module source code how will I know what's available? Some one (or some THING) has to tell me what I can do and explain how to use those features I'm allowed to use, otherwise the whole thing is useless to me. Those developing higher-level abstractions based on fundamental classes and methods via imported modules are presented with a specification DOCUMENT -- NOT the actual source code. The module spec describes all the features intended to be visible to the client developer. When dealing with large projects and software project teams, the actual implementation of a module should ALWAYS remain hidden from those using it -- it's a blackbox with an interface to the outside world. For OOD purists, I believe the techie terms are "decoupling" and "coherence". The module user need only know the interface methods without being burden with the details of implementation. A module should NEVER be changed without first changing its underlying spec document, which may require review / approval in some organizations prior to changing the code. As hobby programmer (retired now), I start a new module with the spec doc actually written out as a giant comment block at the top of the module, this will be the part the user actually sees in the spec library. Since it's just me, I've yet to set up a library, but it would be easy enough to do. Then I begin coding by writing the various classes and methods but without functional bodies -- just null print statements like "print()" -- just enough to allow the module to compile without syntax errors. When this step is complete I compile the completed null-module -- this is my spec. If I were working on a project team, I would present this spec/interface for review & commentary before proceeding with fleshing out the body. I flesh out the bodies of each method one at a time and compile accordingly, ensuring syntax errors are fixed immediately on-the-fly. This is also a good time to start writing a temporary "main" execution section at the bottom to test each method as you code it. When the coding/testing are complete, all of the test code is commented out until you need it again should updates become necessary. In a real-world development team, the spec comment block would also appear in a document control library, but that's another story. The point is: you, as the module client, see only this spec and NOT the source code. PS: long before the beginning of time, I worked in the defense aerospace community and we did some pretty cool stuff, but things like proprietary algorithms and sensitive systems control logic were tightly vaulted and encrypted in super-duper secure software libraries. We had access to module / package interfaces but NOT the blackbox implementation bodies. There was a document management tool that handled all system-level designs, software specs, source code and test records -- it was all synched together. The government had strict requirements software quality assurance standards. Anyone remember a language called "Ada"? That's how old I am!
1
82
0
How can I make methods and data members private in Python? Or doesn't Python support private members?
Private members in Python
0.044415
0
0
66,228
2,064,673
2010-01-14T14:19:00.000
0
0
0
0
python,django,google-app-engine,facebook
2,681,563
1
false
1
0
Honza: we where looking for something that also does authentication Django style. We ended up doing the login on the client side than sending an AJAX request to Django and wrote our own authenticate/login logic. Once we get the user's credentials, we use PyFacebook for FB connectivity.
1
0
0
We are building a website on Google App Engine, using django patch. We would like to use Facebook connect for two purposes: Authenticate users. Access user's social data. Searching for a solution in the usual places (google, FB, SO) brigs up a lot of noise, many partial solutions and no clear answer. So the question is this: does anyone has a clear working solution? maybe even a recipe? Thanks.
Facebook connect on Google App Engine with Django Patch
0
0
0
322
2,065,331
2010-01-14T15:43:00.000
1
0
1
0
python
2,065,418
4
false
0
0
the more secure way is to do everything at the back end. Users just key in the necessary parameters. For example you can prompt them to key in numeric values for foo(), boo() and do(). Then at the back end, pass these values to appropriate functions to do the calculations.
2
4
0
I want to take an input from the user may be like foo() > 90 and boo() == 9 or do() > 100 and use eval on the server side to to evaluate this expression. For security I want to restrict user to add limited functions and operators by keeping a check (against some data-structure) before I pass it to eval function. PS: Input comes from a web page Thanks
Parsing, securing python expression before passing it to eval()
0.049958
0
0
379
2,065,331
2010-01-14T15:43:00.000
1
0
1
0
python
2,065,491
4
false
0
0
You need to lock down the input format, or it will be a gaping security hole. Either implement a full blown parser, as lpthnc suggests, with a reasonable set of operations (but no more), or at least use a regular expression (or several regex patterns in a matching hierarchy and/or loop) to strip out recognized patterns, and reject suspicious entries as "not allowed".
2
4
0
I want to take an input from the user may be like foo() > 90 and boo() == 9 or do() > 100 and use eval on the server side to to evaluate this expression. For security I want to restrict user to add limited functions and operators by keeping a check (against some data-structure) before I pass it to eval function. PS: Input comes from a web page Thanks
Parsing, securing python expression before passing it to eval()
0.049958
0
0
379
2,066,259
2010-01-14T17:49:00.000
0
0
0
0
python,graph,plot,graphviz,complement
2,066,328
2
false
0
0
Compute the complement yourself, then plot it.
1
2
0
Any function in that Graphviz which can do that? If not, any other free software that can do that?
How to draw complement of a network graph?
0
0
1
2,271
2,066,508
2010-01-14T18:26:00.000
15
1
1
0
python,python-unittest
42,430,138
7
false
0
0
Simply placing @unittest.SkipTest decorator above the test is enough.
2
159
0
How can individual unit tests be temporarily disabled when using the unittest module in Python?
Disable individual Python unit tests temporarily
1
0
0
78,791
2,066,508
2010-01-14T18:26:00.000
5
1
1
0
python,python-unittest
2,066,777
7
false
0
0
I just rename a test case method with an underscore: test_myfunc becomes _test_myfunc.
2
159
0
How can individual unit tests be temporarily disabled when using the unittest module in Python?
Disable individual Python unit tests temporarily
0.141893
0
0
78,791
2,066,767
2010-01-14T19:04:00.000
-1
0
0
0
python,multithreading,pygtk
2,069,788
4
false
0
1
the same may be achieved using gobject.idle_add method whose syntax is same as above,you have to import the module gobject
2
8
0
I am using PyGTK to build a GUI application. I want to update the textview widget from another thread but the widget is not getting updated everytime i try an update. What should i do to get a reliable GUI updating?
GUI not updated from another thread when using PyGtk
-0.049958
0
0
3,639
2,066,767
2010-01-14T19:04:00.000
-1
0
0
0
python,multithreading,pygtk
3,030,804
4
false
0
1
What Johannes said is correct, however since GTK is a wrapper for the glib and gobject things, you would actually want to use gtk.idle_add(). No need for the unnecessary imports.
2
8
0
I am using PyGTK to build a GUI application. I want to update the textview widget from another thread but the widget is not getting updated everytime i try an update. What should i do to get a reliable GUI updating?
GUI not updated from another thread when using PyGtk
-0.049958
0
0
3,639
2,066,810
2010-01-14T19:09:00.000
0
0
0
0
python,sockets
2,066,907
4
false
0
0
You sure the client is not hanging up on the server? This is a bit too vague to really tell what is up, but generally a server that is accepting data from a client will quit the connection of the read returns no data.
2
10
0
I'm writing a client/server application in Python and I'm finding it necessary to get a new connection to the server for each request from the client. My server is just inheriting from TCPServer and I'm inheriting from BaseRequestHandler to do my processing. I'm not calling self.request.close() anywhere in the handler, but somehow the server seems to be hanging up on my client. What's up?
Does the TCPServer + BaseRequestHandler in Python's SocketServer close the socket after each call to handle()?
0
0
1
9,010
2,066,810
2010-01-14T19:09:00.000
9
0
0
0
python,sockets
2,072,002
4
true
0
0
Okay, I read the code (on my Mac, SocketServer.py is at /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/). Indeed, TCPServer is closing the connection. In BaseServer.handle_request, process_request is called, which calls close_request. In the TCPServer class, close_request calls self.request.close(), and self.request is just the socket used to handle the request. So the answer to my question is "Yes".
2
10
0
I'm writing a client/server application in Python and I'm finding it necessary to get a new connection to the server for each request from the client. My server is just inheriting from TCPServer and I'm inheriting from BaseRequestHandler to do my processing. I'm not calling self.request.close() anywhere in the handler, but somehow the server seems to be hanging up on my client. What's up?
Does the TCPServer + BaseRequestHandler in Python's SocketServer close the socket after each call to handle()?
1.2
0
1
9,010
2,067,185
2010-01-14T20:00:00.000
2
0
0
0
python,django,logging
2,067,231
1
true
1
0
Yes, the last_login column of the user's record in table auth_user is updated with the date/time of the successful login.
1
1
0
All.. I have a Django site and to access it all the users have to go through the login page. My question is when a user is given a access through the login page to enter the site.Does Django logs the username in any of the Django internal tables.... Thanks.......
Does Django logs usernames internally
1.2
0
0
66
2,067,637
2010-01-14T21:17:00.000
3
0
1
0
python,dll,stack
2,067,700
4
false
0
0
The functions in a dll can have no control over the stack size available when they are executed (unless you spawn new threads under the control of your library). If the dll is custom, then can't you allocate on the heap rather than stack (or statically allocate, if appropriate), and stop the problem that way?
1
10
0
I have a python program that uses a custom-built DLL. This DLL crashes due to a stack overflow. This overflow is not due to a recursive function gone bad, but to large allocations on the stack using alloca(). I want to increase stack size to get rid of this error. Is there any way to do this?
How do I increase the stack size in python
0.148885
0
0
12,672
2,067,749
2010-01-14T21:35:00.000
2
1
1
0
python,dictionary,disk,pickle
2,068,000
2
false
0
0
JSON and YAML work well, also. Depends on what you mean by "efficient"? Size of file? Time required? Amount of code you need to write? You have the timeit module available to determine what meets your specific criteria for "efficient".
1
5
0
What is the most efficient method to store a Python dictionary on the disk? The only methods I know of right now are plain-text and the pickle module. Edit: Sorry for not being very clear. By efficient I meant fastest execution speed. The dictionary will contain mutable objects that will hold information to be parsed and modified.
Efficient method to store Python dictionary on disk?
0.197375
0
0
5,666
2,067,907
2010-01-14T22:03:00.000
3
1
0
1
python,ruby,perl,scripting
2,067,929
7
true
0
0
Python (combined with PyQt) is a very solid combination for GUI desktop applications (note that while QT is LGPL, PyQt (the Python bindings) is dual licensed: GPL or commercial). It offers the same (GUI library-wise) as Qt on C++ but with Python's specific strenghts. I'll list some of the more obvious ones: rapid prototyping extremely readable (hence maintainable) code Should I stick with C(++) for desktop apps? In general: no, unless you want to / need to (for a specific reason).
4
3
0
So I'm aware of the big ammount of general-purpose scripting languages like Ruby, Python, Perl, maybe even PHP, etc. that actually claim being usable for creating desktop applications too. I think my question can be answered clearly Are there actually companies using a special scripting language only to create their applications? Are there any real advantages on creating a product in a language like Python only? I'm not talking about the viability of those languages for web-development! Should I stick with C(++) for desktop apps? best regards, lamas
"Real" and non-embedded use of Ruby, Python and their friends
1.2
0
0
464
2,067,907
2010-01-14T22:03:00.000
6
1
0
1
python,ruby,perl,scripting
2,068,161
7
false
0
0
The company I work for uses Perl and Tk with PerlApp to build executable packages to produce or major software application. Perl beats C and C++ for simplicity of code. You can do things in one line of Perl that take 20 lines of C. We've used WxPerl for a few smaller projects. We'd like to move fully to WxPerl, but existing code works, so the move has a low priority until Wx can give us something we need that Tk can't. Python is popular for building GUI apps, too. You may have heard about Chandler. That's a big Python app. There are many others as well. Ruby is also a suitable choice. PHP is breaking into the world of command line apps. I am not sure about the power or flexibility of its GUI toolkits.
4
3
0
So I'm aware of the big ammount of general-purpose scripting languages like Ruby, Python, Perl, maybe even PHP, etc. that actually claim being usable for creating desktop applications too. I think my question can be answered clearly Are there actually companies using a special scripting language only to create their applications? Are there any real advantages on creating a product in a language like Python only? I'm not talking about the viability of those languages for web-development! Should I stick with C(++) for desktop apps? best regards, lamas
"Real" and non-embedded use of Ruby, Python and their friends
1
0
0
464
2,067,907
2010-01-14T22:03:00.000
2
1
0
1
python,ruby,perl,scripting
2,072,473
7
false
0
0
I would recommend you not try to look for a language that is best for GUI apps but instead look for the language that you like the most and then use that to write your app. Ruby, Python, Perl all have GUI tool kits available to them. Most of them have access to the same often used tool kits like TK, GTK, and Wx. The look and feel of a an app will be dependent more on the GUI tool kit than on the language, and performance wise your likely to see more impact for how you write your app than language choice. If your comfortable with C++ then you should also look at C# or Java as options. While not scripting languages they have many of the same benefits like memory management and more sane string implementations.
4
3
0
So I'm aware of the big ammount of general-purpose scripting languages like Ruby, Python, Perl, maybe even PHP, etc. that actually claim being usable for creating desktop applications too. I think my question can be answered clearly Are there actually companies using a special scripting language only to create their applications? Are there any real advantages on creating a product in a language like Python only? I'm not talking about the viability of those languages for web-development! Should I stick with C(++) for desktop apps? best regards, lamas
"Real" and non-embedded use of Ruby, Python and their friends
0.057081
0
0
464
2,067,907
2010-01-14T22:03:00.000
1
1
0
1
python,ruby,perl,scripting
2,068,564
7
false
0
0
I have used a number of programs that were developed using scripted languages. Several embedded device vendors ship my group Windows-based configuration and debugging utilities written in TCL. Google's drawing program SketchUp has a lot of Ruby inside it (and users can create add-ons using Ruby). I have seen many Linux applications written in Python. There are many more examples out there, but often times finished applications are bundled up to the point where you can't really tell what's powering it on the inside. Yes, there can be advantages to working with scripted languages. Some scripted languages make it easier to do specific tasks; for example, text processing is much easier (IMO) in a language like Ruby that has regular expression support and a robust String class than it is in plain old C. Generating a UI using a scripted language may make it easier to support multiple platforms, as all the platform-specific code is taken care of inside the language interpreter or pre-compiled libraries. For example, our suppliers who build TCL-based apps claim they can build the UI for an app using TCL in a fraction of the time it would take them to build it in C++ or VB, and then they can port it to Linux almost effortlessly. On the other hand there are a few things that scripted languages typically aren't suited for, such as writing drivers or doing anything that requires low-level hardware access. Most importantly, however, is this: modern languages have become quite powerful to the point where choice of language doesn't make as big of a difference as it used to be. Use the language you are most comfortable with. The learning curve associated with learning a new language will usually have a much larger impact on your project.
4
3
0
So I'm aware of the big ammount of general-purpose scripting languages like Ruby, Python, Perl, maybe even PHP, etc. that actually claim being usable for creating desktop applications too. I think my question can be answered clearly Are there actually companies using a special scripting language only to create their applications? Are there any real advantages on creating a product in a language like Python only? I'm not talking about the viability of those languages for web-development! Should I stick with C(++) for desktop apps? best regards, lamas
"Real" and non-embedded use of Ruby, Python and their friends
0.028564
0
0
464
2,068,473
2010-01-15T00:04:00.000
1
0
0
0
python,tokyo-cabinet
2,384,015
2
true
0
0
This depend on no-sql implementation. Cassandra, for example, allows range queries, so you could model data to do queries on last name, or with full name (starting with last name, then first name). Beyond this, many simpler key-value stores would indeed require you to store a list structure (or such) for multi-valued entries. Whether this is feasible or not depends on expected number of "duplicates" -- with last name, number could be rather high I presume, so it does not sound like an ideal model for many cases.
1
1
0
i have been in the RDBMS world for many years now but wish to explore the whole nosql movement. so here's my first question: is it bad practice to have the possibility of duplicate keys? for example, an address book keyed off of last name (most probably search item?) could have multiple entities. is it bad practice to use the last name then? is the key supposed to be the most "searchable" definition of the entity? are there any resources for "best practices" in this whole new world (for me)? i'm intrigued by tokyo cabinet (and specifically the tc interface) but don't know how to iterate through different entities that have the same key (e.g. see above). i can only get the first entity. anyway, thanks in advance for the help
key/value (general) and tokyo cabinet (python tc-specific) question
1.2
1
0
597
2,068,486
2010-01-15T00:06:00.000
1
1
1
0
python,macos,documentation,reference,widget
2,068,830
4
true
0
0
Python libraries have (or should have) built in documentation through docstrings. Also, python code is (mostly) very readable, and reading the source (.py or even .c) is actually the preferred way for many developers to get the information they're looking for, especially since some corner cases may not even be documented. I've caught myself looking through the source now and then, as if it's a natural step in looking up functionality, either because I'm curious how they solve the problem, or because I reckon it's faster than googling obscure problems and reading SO questions.
2
3
0
There're tons of apps/widgets for PHP function reference and even for Ruby but I'm shocked to find there is nothing available for a popular language like Python (besides the official online documentation ofcourse). Is there really not a single handy reference widget/app available for Python? I have 'Pocket Reference' book, but a dashboard widget would be so handy!
Python Function Reference
1.2
0
0
657
2,068,486
2010-01-15T00:06:00.000
0
1
1
0
python,macos,documentation,reference,widget
2,069,084
4
false
0
0
The interactive interpreter is a fantastic reference tool. dir(<identifier) lists all the attributes of a module, class, or function help(<identifier>) gives you help about same. pydoc at the command line is another great tool. It does for Python what man gives you for commands, plus it even includes a web server you can start up to see the documentation in your browser.
2
3
0
There're tons of apps/widgets for PHP function reference and even for Ruby but I'm shocked to find there is nothing available for a popular language like Python (besides the official online documentation ofcourse). Is there really not a single handy reference widget/app available for Python? I have 'Pocket Reference' book, but a dashboard widget would be so handy!
Python Function Reference
0
0
0
657
2,069,739
2010-01-15T05:46:00.000
0
0
0
0
wxpython,focus
2,135,083
2
false
0
1
You could also give the focus to another control in your event handler for the buttons. Just call the SetFocus() method on any other control. This might make your application more usable as a side effect if you for example return focus to a text field that is likely to be typed in next.
1
0
0
I don't know if this is a stupid question, but is there any way to not show focus in wxPython? For example, I built a simple GUI with a few buttons and I don't want the dotted rectangle to show up on the button I have just clicked. If I remember correctly in Excel VBA you could just set TakeFocusOnClick tag to False. What would be the equivalent in wxPython?
Not showing focus in wxPython?
0
0
0
197
2,070,643
2010-01-15T09:53:00.000
6
0
1
0
python,list,collections
2,070,700
13
false
0
0
I'm not sure what the objection to a for loop is: there is no multiset in Python so you can't use a builtin container to help you out. Seems to me anything on one line (if possible) will probably be helishly complex to understand. Go for readability and KISS. Python is not C :)
1
52
0
In Python, How can one subtract two non-unique, unordered lists? Say we have a = [0,1,2,1,0] and b = [0, 1, 1] I'd like to do something like c = a - b and have c be [2, 0] or [0, 2] order doesn't matter to me. This should throw an exception if a does not contain all elements in b. Note this is different from sets! I'm not interested in finding the difference of the sets of elements in a and b, I'm interested in the difference between the actual collections of elements in a and b. I can do this with a for loop, looking up the first element of b in a and then removing the element from b and from a, etc. But this doesn't appeal to me, it would be very inefficient (order of O(n^2) time) while it should be no problem to do this in O(n log n) time.
Subtracting two lists in Python
1
0
0
141,082
2,074,071
2010-01-15T19:07:00.000
2
1
1
0
python,import
2,074,086
2
true
0
0
You can include the path of foo.py in the PYTHONPATH environment variable. The interpreter will look also the directories contained there, so you can make the import just like it was on the same directory.
1
0
0
I have a third-party Python script (foo.py) in a folder that is in my system path (but not the Python sys.path). foo.py is not part of any Python module. I am writing another script (bar.py) in which I'd like to call a function located in foo.py. Is this possible? Can it be done without explicitly naming the folder of foo.py? Thanks.
Use function from Python script in OS path
1.2
0
0
197
2,074,074
2010-01-15T19:08:00.000
0
1
1
0
python,multithreading,unit-testing,performance,multicore
35,182,727
4
false
0
0
As the @vinay-sajip suggested, a few non-core python packages like py.test and nose provided parallel execution of unit tests via multiprocessing lib right out of the box. However, one thing to consider is that if you are testing a web app with database backend and majority of your test cases are relying on connecting to the same test database, then your unit test execution speed is bottlenecked on the DB not I/O per se. And using multiprocess won't speed it up. Given that each unit test case requires an independent setup of the database schema + data, you cannot scale out the execution speed only on CPU but restricted with a single test database connection to a single test database server (otherwise the state of the data may interfere with other other while parallel executing each test case so on and so forth).
1
13
0
I'm using python unittest in order to test some other external application but it takes too much time to run the test one by one. I would like to know how can I speedup this process by using the power of multi-cores. Can I tweak unittest to execute tests in parallel? How? This question is not able python GIL limitation because in fact not the python code takes time but the external application that I execute, currently via os.system().
How to speedup python unittest on muticore machines?
0
0
0
9,389
2,076,582
2010-01-16T07:40:00.000
1
0
0
0
python,mysql,performance,svn
2,077,129
3
false
0
0
It is "well known", so to speak, that svn update waits up to a whole second after it has finished running, so that file modification timestamps get "in the past" (since many filesystems don't have a timestamp granularity finer than one second). You can find more information about it by Googling for "svn sleep_for_timestamps". I don't have any obvious solution to suggest. If this is really performance critical you could either: 1) not update as often as you are doing 2) try to use a lower-level Subversion API (good luck).
3
2
0
I have a script with a main for loop that repeats about 15k times. In this loop it queries a local MySQL database and does a SVN update on a local repository. I placed the SVN repository in a RAMdisk as before most of the time seemed to be spent reading/writing to disk. Now I have a script that runs at basically the same speed but CPU utilization for that script never goes over 10%. ProcessExplorer shows that mysqld is also not taking almost any CPU time or reading/writing a lot to disk. What steps would you take to figure out where the bottleneck is?
Finding the performance bottleneck in a Python and MySQL script
0.066568
1
0
917
2,076,582
2010-01-16T07:40:00.000
4
0
0
0
python,mysql,performance,svn
2,076,639
3
true
0
0
Doing SQL queries in a for loop 15k times is a bottleneck in every language.. Is there any reason you query every time again ? If you do a single query before the for loop and then loop over the resultset and the SVN part, you will see a dramatic increase in speed. But I doubt that you will get a higher CPU usage. The reason is that you are not doing calculations, but mostly IO. Btw, you can't measure that in mysqld cpu usage, as it's in the actual code not complexity of the queries, but their count and the latency of the server engine to answer. So you will see only very short, not expensive queries, that do sum up in time, though.
3
2
0
I have a script with a main for loop that repeats about 15k times. In this loop it queries a local MySQL database and does a SVN update on a local repository. I placed the SVN repository in a RAMdisk as before most of the time seemed to be spent reading/writing to disk. Now I have a script that runs at basically the same speed but CPU utilization for that script never goes over 10%. ProcessExplorer shows that mysqld is also not taking almost any CPU time or reading/writing a lot to disk. What steps would you take to figure out where the bottleneck is?
Finding the performance bottleneck in a Python and MySQL script
1.2
1
0
917
2,076,582
2010-01-16T07:40:00.000
1
0
0
0
python,mysql,performance,svn
2,076,590
3
false
0
0
Profile your Python code. That will show you how long each function/method call takes. If that's the method call querying the MySQL database, you'll have a clue where to look. But it also may be something else. In any case, profiling is the usual approach to solve such problems.
3
2
0
I have a script with a main for loop that repeats about 15k times. In this loop it queries a local MySQL database and does a SVN update on a local repository. I placed the SVN repository in a RAMdisk as before most of the time seemed to be spent reading/writing to disk. Now I have a script that runs at basically the same speed but CPU utilization for that script never goes over 10%. ProcessExplorer shows that mysqld is also not taking almost any CPU time or reading/writing a lot to disk. What steps would you take to figure out where the bottleneck is?
Finding the performance bottleneck in a Python and MySQL script
0.066568
1
0
917
2,076,678
2010-01-16T08:19:00.000
1
0
0
0
python,django,design-patterns,application-design
2,078,384
1
true
1
0
it is design decision. it depends to your design and programming interests. i used the combination of three methods you said. if i need to some informations that can be build from other fields then i will create an internal function in model class. if i need other records of database to do something i will create an function outside of model class. and other unusual needs will be computed everywhere i need them.
1
3
0
I am building an application that will send an API call and save the resulting information after processing the information in a APIRecord(models.Model) class. 1) Should I build a separate class in such a way that the class does the API call, processes the information (including checking against business rules) and then creates an instance of my APIRecord() class? Or 2) Should I build a separate class with the appropriate methods for processing, and calling the API, and then in my model, override the APIRecord.save() method to call the separate class's API methods and then save the results? Or 3) Should I build my model class with the appropriate methods for calling the API and processing the response (including checking for certain values and other business rules)? I tried # 2 and ran into problems with flexibility (but am still open to suggestion). I'm leaning towards # 1, but I'm not sure of all the negatives yet?
Django: Chicken or Egg question
1.2
0
0
297
2,076,838
2010-01-16T09:27:00.000
5
0
1
0
python,random,numbers
2,077,313
17
false
0
0
I think you are overestimating the problems with approach 1). Unless you have hard-realtime requirements just checking by random choice terminates rather fast. The probability of needing more than a number of iterations decays exponentially. With 100M numbers outputted (10% fillfactor) you'll have one in billion chance of requiring more than 9 iterations. Even with 50% of numbers taken you'll on average need 2 iterations and have one in a billion chance of requiring more than 30 checks. Or even the extreme case where 99% of the numbers are already taken might still be reasonable - you'll average a 100 iterations and have 1 in a billion change of requiring 2062 iterations
5
38
0
Ok this is one of those trickier than it sounds questions so I'm turning to stack overflow because I can't think of a good answer. Here is what I want: I need Python to generate a simple a list of numbers from 0 to 1,000,000,000 in random order to be used for serial numbers (using a random number so that you can't tell how many have been assigned or do timing attacks as easily, i.e. guessing the next one that will come up). These numbers are stored in a database table (indexed) along with the information linked to them. The program generating them doesn't run forever so it can't rely on internal state. No big deal right? Just generate a list of numbers, shove them into an array and use Python "random.shuffle(big_number_array)" and we're done. Problem is I'd like to avoid having to store a list of numbers (and thus read the file, pop one off the top, save the file and close it). I'd rather generate them on the fly. Problem is that the solutions I can think of have problems: 1) Generate a random number and then check if it has already been used. If it has been used generate a new number, check, repeat as needed until I find an unused one. Problem here is that I may get unlucky and generate a lot of used numbers before getting one that is unused. Possible fix: use a very large pool of numbers to reduce the chances of this (but then I end up with silly long numbers). 2) Generate a random number and then check if it has already been used. If it has been used add or subtract one from the number and check again, keep repeating until I hit an unused number. Problem is this is no longer a random number as I have introduced bias (eventually I will get clumps of numbers and you'd be able to predict the next number with a better chance of success). 3) Generate a random number and then check if it has already been used. If it has been used add or subtract another randomly generated random number and check again, problem is we're back to simply generating random numbers and checking as in solution 1. 4) Suck it up and generate the random list and save it, have a daemon put them into a Queue so there are numbers available (and avoid constantly opening and closing a file, batching it instead). 5) Generate much larger random numbers and hash them (i.e. using MD5) to get a smaller numeric value, we should rarely get collisions, but I end up with larger than needed numbers again. 6) Prepend or append time based information to the random number (i.e. unix timestamp) to reduce chances of a collision, again I get larger numbers than I need. Anyone have any clever ideas that will reduce the chances of a "collision" (i.e. generating a random number that is already taken) but will also allow me to keep the number "small" (i.e. less than a billion (or a thousand million for your europeans =)). Answer and why I accepted it: So I will simply go with 1, and hope it's not an issue, however if it is I will go with the deterministic solution of generating all the numbers and storing them so that there is a guarentee of getting a new random number, and I can use "small" numbers (i.e. 9 digits instead of an MD5/etc.).
Generating non-repeating random numbers in Python
0.058756
0
0
30,464
2,076,838
2010-01-16T09:27:00.000
1
0
1
0
python,random,numbers
2,083,392
17
false
0
0
You can run 1) without running into the problem of too many wrong random numbers if you just decrease the random interval by one each time. For this method to work, you will need to save the numbers already given (which you want to do anyway) and also save the quantity of numbers taken. It is pretty obvious that, after having collected 10 numbers, your pool of possible random numbers will have been decreased by 10. Therefore, you must not choose a number between 1 and 1.000.000 but between 1 an 999.990. Of course this number is not the real number but only an index (unless the 10 numbers collected have been 999.991, 999.992, …); you’d have to count now from 1 omitting all the numbers already collected. Of course, your algorithm should be smarter than just counting from 1 to 1.000.000 but I hope you understand the method. I don’t like drawing random numbers until I get one which fits either. It just feels wrong.
5
38
0
Ok this is one of those trickier than it sounds questions so I'm turning to stack overflow because I can't think of a good answer. Here is what I want: I need Python to generate a simple a list of numbers from 0 to 1,000,000,000 in random order to be used for serial numbers (using a random number so that you can't tell how many have been assigned or do timing attacks as easily, i.e. guessing the next one that will come up). These numbers are stored in a database table (indexed) along with the information linked to them. The program generating them doesn't run forever so it can't rely on internal state. No big deal right? Just generate a list of numbers, shove them into an array and use Python "random.shuffle(big_number_array)" and we're done. Problem is I'd like to avoid having to store a list of numbers (and thus read the file, pop one off the top, save the file and close it). I'd rather generate them on the fly. Problem is that the solutions I can think of have problems: 1) Generate a random number and then check if it has already been used. If it has been used generate a new number, check, repeat as needed until I find an unused one. Problem here is that I may get unlucky and generate a lot of used numbers before getting one that is unused. Possible fix: use a very large pool of numbers to reduce the chances of this (but then I end up with silly long numbers). 2) Generate a random number and then check if it has already been used. If it has been used add or subtract one from the number and check again, keep repeating until I hit an unused number. Problem is this is no longer a random number as I have introduced bias (eventually I will get clumps of numbers and you'd be able to predict the next number with a better chance of success). 3) Generate a random number and then check if it has already been used. If it has been used add or subtract another randomly generated random number and check again, problem is we're back to simply generating random numbers and checking as in solution 1. 4) Suck it up and generate the random list and save it, have a daemon put them into a Queue so there are numbers available (and avoid constantly opening and closing a file, batching it instead). 5) Generate much larger random numbers and hash them (i.e. using MD5) to get a smaller numeric value, we should rarely get collisions, but I end up with larger than needed numbers again. 6) Prepend or append time based information to the random number (i.e. unix timestamp) to reduce chances of a collision, again I get larger numbers than I need. Anyone have any clever ideas that will reduce the chances of a "collision" (i.e. generating a random number that is already taken) but will also allow me to keep the number "small" (i.e. less than a billion (or a thousand million for your europeans =)). Answer and why I accepted it: So I will simply go with 1, and hope it's not an issue, however if it is I will go with the deterministic solution of generating all the numbers and storing them so that there is a guarentee of getting a new random number, and I can use "small" numbers (i.e. 9 digits instead of an MD5/etc.).
Generating non-repeating random numbers in Python
0.011764
0
0
30,464
2,076,838
2010-01-16T09:27:00.000
4
0
1
0
python,random,numbers
2,077,409
17
false
0
0
The standard Linear Congruential random number generator's seed sequence CANNOT repeat until the full set of numbers from the starting seed value have been generated. Then it MUST repeat precisely. The internal seed is often large (48 or 64 bits). The generated numbers are smaller (32 bits usually) because the entire set of bits are not random. If you follow the seed values they will form a distinct non-repeating sequence. The question is essentially one of locating a good seed that generates "enough" numbers. You can pick a seed, and generate numbers until you get back to the starting seed. That's the length of the sequence. It may be millions or billions of numbers. There are some guidelines in Knuth for picking suitable seeds that will generate very long sequences of unique numbers.
5
38
0
Ok this is one of those trickier than it sounds questions so I'm turning to stack overflow because I can't think of a good answer. Here is what I want: I need Python to generate a simple a list of numbers from 0 to 1,000,000,000 in random order to be used for serial numbers (using a random number so that you can't tell how many have been assigned or do timing attacks as easily, i.e. guessing the next one that will come up). These numbers are stored in a database table (indexed) along with the information linked to them. The program generating them doesn't run forever so it can't rely on internal state. No big deal right? Just generate a list of numbers, shove them into an array and use Python "random.shuffle(big_number_array)" and we're done. Problem is I'd like to avoid having to store a list of numbers (and thus read the file, pop one off the top, save the file and close it). I'd rather generate them on the fly. Problem is that the solutions I can think of have problems: 1) Generate a random number and then check if it has already been used. If it has been used generate a new number, check, repeat as needed until I find an unused one. Problem here is that I may get unlucky and generate a lot of used numbers before getting one that is unused. Possible fix: use a very large pool of numbers to reduce the chances of this (but then I end up with silly long numbers). 2) Generate a random number and then check if it has already been used. If it has been used add or subtract one from the number and check again, keep repeating until I hit an unused number. Problem is this is no longer a random number as I have introduced bias (eventually I will get clumps of numbers and you'd be able to predict the next number with a better chance of success). 3) Generate a random number and then check if it has already been used. If it has been used add or subtract another randomly generated random number and check again, problem is we're back to simply generating random numbers and checking as in solution 1. 4) Suck it up and generate the random list and save it, have a daemon put them into a Queue so there are numbers available (and avoid constantly opening and closing a file, batching it instead). 5) Generate much larger random numbers and hash them (i.e. using MD5) to get a smaller numeric value, we should rarely get collisions, but I end up with larger than needed numbers again. 6) Prepend or append time based information to the random number (i.e. unix timestamp) to reduce chances of a collision, again I get larger numbers than I need. Anyone have any clever ideas that will reduce the chances of a "collision" (i.e. generating a random number that is already taken) but will also allow me to keep the number "small" (i.e. less than a billion (or a thousand million for your europeans =)). Answer and why I accepted it: So I will simply go with 1, and hope it's not an issue, however if it is I will go with the deterministic solution of generating all the numbers and storing them so that there is a guarentee of getting a new random number, and I can use "small" numbers (i.e. 9 digits instead of an MD5/etc.).
Generating non-repeating random numbers in Python
0.047024
0
0
30,464
2,076,838
2010-01-16T09:27:00.000
0
0
1
0
python,random,numbers
2,076,898
17
false
0
0
I'd rethink the problem itself... You don't seem to be doing anything sequential with the numbers... and you've got an index on the column which has them. Do they actually need to be numbers? Consider a sha hash... you don't actually need the entire thing. Do what git or other url shortening services do, and take first 3/4/5 characters of the hash. Given that each character now has 36 possible values instead of 10, you have 2,176,782,336 combinations instead of 999,999 combinations (for six digits). Combine that with a quick check on whether the combination exists (a pure index query) and a seed like a timestamp + random number and it should do for almost any situation.
5
38
0
Ok this is one of those trickier than it sounds questions so I'm turning to stack overflow because I can't think of a good answer. Here is what I want: I need Python to generate a simple a list of numbers from 0 to 1,000,000,000 in random order to be used for serial numbers (using a random number so that you can't tell how many have been assigned or do timing attacks as easily, i.e. guessing the next one that will come up). These numbers are stored in a database table (indexed) along with the information linked to them. The program generating them doesn't run forever so it can't rely on internal state. No big deal right? Just generate a list of numbers, shove them into an array and use Python "random.shuffle(big_number_array)" and we're done. Problem is I'd like to avoid having to store a list of numbers (and thus read the file, pop one off the top, save the file and close it). I'd rather generate them on the fly. Problem is that the solutions I can think of have problems: 1) Generate a random number and then check if it has already been used. If it has been used generate a new number, check, repeat as needed until I find an unused one. Problem here is that I may get unlucky and generate a lot of used numbers before getting one that is unused. Possible fix: use a very large pool of numbers to reduce the chances of this (but then I end up with silly long numbers). 2) Generate a random number and then check if it has already been used. If it has been used add or subtract one from the number and check again, keep repeating until I hit an unused number. Problem is this is no longer a random number as I have introduced bias (eventually I will get clumps of numbers and you'd be able to predict the next number with a better chance of success). 3) Generate a random number and then check if it has already been used. If it has been used add or subtract another randomly generated random number and check again, problem is we're back to simply generating random numbers and checking as in solution 1. 4) Suck it up and generate the random list and save it, have a daemon put them into a Queue so there are numbers available (and avoid constantly opening and closing a file, batching it instead). 5) Generate much larger random numbers and hash them (i.e. using MD5) to get a smaller numeric value, we should rarely get collisions, but I end up with larger than needed numbers again. 6) Prepend or append time based information to the random number (i.e. unix timestamp) to reduce chances of a collision, again I get larger numbers than I need. Anyone have any clever ideas that will reduce the chances of a "collision" (i.e. generating a random number that is already taken) but will also allow me to keep the number "small" (i.e. less than a billion (or a thousand million for your europeans =)). Answer and why I accepted it: So I will simply go with 1, and hope it's not an issue, however if it is I will go with the deterministic solution of generating all the numbers and storing them so that there is a guarentee of getting a new random number, and I can use "small" numbers (i.e. 9 digits instead of an MD5/etc.).
Generating non-repeating random numbers in Python
0
0
0
30,464
2,076,838
2010-01-16T09:27:00.000
0
0
1
0
python,random,numbers
2,077,000
17
false
0
0
Do you need this to be cryptographically secure or just hard to guess? How bad are collisions? Because if it needs to be cryptographically strong and have zero collisions, it is, sadly, impossible.
5
38
0
Ok this is one of those trickier than it sounds questions so I'm turning to stack overflow because I can't think of a good answer. Here is what I want: I need Python to generate a simple a list of numbers from 0 to 1,000,000,000 in random order to be used for serial numbers (using a random number so that you can't tell how many have been assigned or do timing attacks as easily, i.e. guessing the next one that will come up). These numbers are stored in a database table (indexed) along with the information linked to them. The program generating them doesn't run forever so it can't rely on internal state. No big deal right? Just generate a list of numbers, shove them into an array and use Python "random.shuffle(big_number_array)" and we're done. Problem is I'd like to avoid having to store a list of numbers (and thus read the file, pop one off the top, save the file and close it). I'd rather generate them on the fly. Problem is that the solutions I can think of have problems: 1) Generate a random number and then check if it has already been used. If it has been used generate a new number, check, repeat as needed until I find an unused one. Problem here is that I may get unlucky and generate a lot of used numbers before getting one that is unused. Possible fix: use a very large pool of numbers to reduce the chances of this (but then I end up with silly long numbers). 2) Generate a random number and then check if it has already been used. If it has been used add or subtract one from the number and check again, keep repeating until I hit an unused number. Problem is this is no longer a random number as I have introduced bias (eventually I will get clumps of numbers and you'd be able to predict the next number with a better chance of success). 3) Generate a random number and then check if it has already been used. If it has been used add or subtract another randomly generated random number and check again, problem is we're back to simply generating random numbers and checking as in solution 1. 4) Suck it up and generate the random list and save it, have a daemon put them into a Queue so there are numbers available (and avoid constantly opening and closing a file, batching it instead). 5) Generate much larger random numbers and hash them (i.e. using MD5) to get a smaller numeric value, we should rarely get collisions, but I end up with larger than needed numbers again. 6) Prepend or append time based information to the random number (i.e. unix timestamp) to reduce chances of a collision, again I get larger numbers than I need. Anyone have any clever ideas that will reduce the chances of a "collision" (i.e. generating a random number that is already taken) but will also allow me to keep the number "small" (i.e. less than a billion (or a thousand million for your europeans =)). Answer and why I accepted it: So I will simply go with 1, and hope it's not an issue, however if it is I will go with the deterministic solution of generating all the numbers and storing them so that there is a guarentee of getting a new random number, and I can use "small" numbers (i.e. 9 digits instead of an MD5/etc.).
Generating non-repeating random numbers in Python
0
0
0
30,464
2,077,522
2010-01-16T13:58:00.000
2
0
0
0
python,mysql,database,django,performance
2,077,536
2
false
0
0
First, the most obvious answer is that you should ask them, not us, since I can tell you this, that design seems bogus deluxe. The only reason I can come up with is that you have inexperienced DBA's that does not know how to performance-tune a database, and seems to think that a table with less rows will always vastly outperform a table with more rows. With good indices, that need not be the case.
1
2
0
I recently joined a new company and the development team was in the progress of a project to rebuild the database categories structure as follows: if we have category and subcategory for items, like food category and italian food category in food category. They were building a table for each category, instead of having one table and a link to the category id. Now we have a table called food and another table called food_italian and both tables contain the same fields. I have asked around and it seems that some DBA prefers this design. I would like to know why? and how this design can improve the performance?
DB a table for the category and another table for the subcategory with similar fields, why?
0.197375
1
0
155
2,079,898
2010-01-17T03:56:00.000
4
0
0
0
python,django
2,080,483
2
true
1
0
Nothing particular happens when you add an app to INSTALLED_APPS, but the main thing that affects you is that its views are checked when you call reverse(). The way reverse works is to import all the views in the project, and see which ones match the URL name you have given. However, it is quite fragile, and if any of the views cause an error for some reason, or can't be imported, the reverse call will fail. The fact that it is only failing once you include app2 indicates that there is an issue with the views in app2 somewhere. Try importing them individually from the shell and see what errors you get. Edited after update Thanks for the extra detail. I have seen this before in my own code. It is probably because the admin files are being imported before the urlconf is processed, so this reverse gives an error. Try moving the admin.autodiscover() line down to the very bottom of urls.py, so that it is the last line in that file.
1
3
0
Here is the situation. I have a django project with two installed apps. Both apps appear to function properly if they are installed independently of each other. However if I list both apps in the settings.INSTALLED_APPS the reverse() function seems to break for urls in the first app. So this leads me to believe that a bug in the second app is causing the problem. If I simply remove app_2 from the settings.INSTALLED_APPS, app_1's url reverse() begins working again. So the question becomes what "Magic" is happening when I add app_2 to the settings.INSTALLED_APPS? Where should I be looking in app_2 for code causing this problem? UPDATE: I have narrowed down the problem a little, but it just gets stranger. app_2 has an admin.py file that defines a few custom admin views. In that file is a line that calls reverse: reverse('init_script_view', args=['id_content']) As long as that line is in the admin.py file all calls to reverse() fail with a NoReverseMatch exception. If I remove that line, everything seems to work fine.
What happen when I add a Django app to INSTALLED_APPS?
1.2
0
0
2,706
2,081,586
2010-01-17T16:06:00.000
63
0
0
0
python,web-scraping,screen-scraping
8,603,040
10
false
1
0
I'd really recommend Scrapy. Quote from a deleted answer: Scrapy crawling is fastest than mechanize because uses asynchronous operations (on top of Twisted). Scrapy has better and fastest support for parsing (x)html on top of libxml2. Scrapy is a mature framework with full unicode, handles redirections, gzipped responses, odd encodings, integrated http cache, etc. Once you are into Scrapy, you can write a spider in less than 5 minutes that download images, creates thumbnails and export the extracted data directly to csv or json.
1
188
0
I'd like to grab daily sunrise/sunset times from a web site. Is it possible to scrape web content with Python? what are the modules used? Is there any tutorial available?
Web scraping with Python
1
0
1
208,635
2,081,836
2010-01-17T17:14:00.000
0
0
1
0
python,file,line
58,380,322
30
false
0
0
If you want to read specific lines, such as line starting after some threshold line then you can use the following codes, file = open("files.txt","r") lines = file.readlines() ## convert to list of lines datas = lines[11:] ## raed the specific lines
2
271
0
I'm using a for loop to read a file, but I only want to read specific lines, say line #26 and #30. Is there any built-in feature to achieve this?
How to read specific lines from a file (by line number)?
0
0
0
709,686
2,081,836
2010-01-17T17:14:00.000
14
0
1
0
python,file,line
3,990,042
30
false
0
0
if you want line 7 line = open("file.txt", "r").readlines()[7]
2
271
0
I'm using a for loop to read a file, but I only want to read specific lines, say line #26 and #30. Is there any built-in feature to achieve this?
How to read specific lines from a file (by line number)?
1
0
0
709,686
2,082,159
2010-01-17T18:49:00.000
1
1
1
0
c#,python,methods,export,python.net
2,082,198
4
false
0
0
(This may no longer be relevant since SLaks has found that ingenious link, but I'll leave an edited version for reference...) The "normal" way of exposing .NET/C# objects to unmanaged code (like Python) is to create a COM-callable wrapper for the C# DLL (.NET assembly), and call that using Python's COM/OLE support. To create the COM-callable wrapper, use the tlbexp and/or regasm command-line utilities. Obviously, however, this does not provide the C/DLL-style API that SLaks' link does.
1
15
0
How can we export C# methods? I have a dll and I want to use its methods in the Python language with the ctypes module. Because I need to use the ctypes module, I need to export the C# methods for them to be visible in Python. So, how can I export the C# methods (like they do in C++)?
How to export C# methods?
0.049958
0
0
8,012
2,083,987
2010-01-18T05:00:00.000
-11
0
1
0
python,loops,exception,try-except
2,085,009
25
false
0
0
increment your loop variable only when the try clause succeeds
1
355
0
I have a loop starting with for i in range(0, 100). Normally it runs correctly, but sometimes it fails due to network conditions. Currently I have it set so that on failure, it will continue in the except clause (continue on to the next number for i). Is it possible for me to reassign the same number to i and run through the failed iteration of the loop again?
How to retry after exception?
-1
0
0
414,290
2,084,063
2010-01-18T05:30:00.000
0
0
0
1
python,memory-management,windows-7,squish
2,175,363
3
false
0
0
Remember that Squish allows remote testing of the application. A system parameter queried via Python directly will only apply to the case of local testing. An approach that works in either case is to call the currentApplicationContext() function that will give you a handle to the Application Under Test. It has a usedMemory property you can query. I don't recall which process property exactly is being queried but it should provide a rough indication.
2
1
0
Recently I've found myself testing an aplication in Froglogic's Squish, using Python to create test scripts. Just the other day, the question of how much memory the program is using has come up, and I've found myself unable to answer it. It seems reasonable to assume that there's a way to query the os (windows 7) API for the information, but I've no idea where to begin. Does anyone know how I'd go about this?
How would I discover the memory used by an application through a python script?
0
0
0
241
2,084,063
2010-01-18T05:30:00.000
-1
0
0
1
python,memory-management,windows-7,squish
2,084,070
3
false
0
0
In command line: tasklist /FO LIST and parse the results? Sorry, I don't know a Pythonic way. =P
2
1
0
Recently I've found myself testing an aplication in Froglogic's Squish, using Python to create test scripts. Just the other day, the question of how much memory the program is using has come up, and I've found myself unable to answer it. It seems reasonable to assume that there's a way to query the os (windows 7) API for the information, but I've no idea where to begin. Does anyone know how I'd go about this?
How would I discover the memory used by an application through a python script?
-0.066568
0
0
241
2,084,508
2010-01-18T07:34:00.000
2
1
0
1
python,terminal
2,084,517
27
false
0
0
You could tear through the terminfo database, but the functions for doing so are in curses anyway.
4
241
0
Does any standard "comes with batteries" method exist to clear the terminal screen from a Python script, or do I have to go curses (the libraries, not the words)?
Clear terminal in Python
0.014814
0
0
516,293
2,084,508
2010-01-18T07:34:00.000
0
1
0
1
python,terminal
4,808,001
27
false
0
0
If all you need is to clear the screen, this is probably good enough. The problem is there's not even a 100% cross platform way of doing this across linux versions. The problem is the implementations of the terminal all support slightly different things. I'm fairly sure that "clear" will work everywhere. But the more "complete" answer is to use the xterm control characters to move the cursor, but that requires xterm in and of itself. Without knowing more of your problem, your solution seems good enough.
4
241
0
Does any standard "comes with batteries" method exist to clear the terminal screen from a Python script, or do I have to go curses (the libraries, not the words)?
Clear terminal in Python
0
0
0
516,293
2,084,508
2010-01-18T07:34:00.000
2
1
0
1
python,terminal
2,084,525
27
false
0
0
python -c "from os import system; system('clear')"
4
241
0
Does any standard "comes with batteries" method exist to clear the terminal screen from a Python script, or do I have to go curses (the libraries, not the words)?
Clear terminal in Python
0.014814
0
0
516,293
2,084,508
2010-01-18T07:34:00.000
108
1
0
1
python,terminal
26,639,250
27
false
0
0
Why hasn't anyone talked about just simply doing Ctrl+L in Windows or Cmd+L in Mac. Surely the simplest way of clearing screen.
4
241
0
Does any standard "comes with batteries" method exist to clear the terminal screen from a Python script, or do I have to go curses (the libraries, not the words)?
Clear terminal in Python
1
0
0
516,293
2,084,969
2010-01-18T09:25:00.000
1
1
0
1
python,macos,deployment,ubuntu,rsync
2,085,042
2
false
0
0
to avoid su www I see two easy choices. make a folder writable to you and readable by www's group in some path that the web-server will be able to serve, then you can rsync to that folder from somewhere on your local machine. put your public ssh key in www's authorized_keys and rsync to the www user (a bit less security in some setups perhaps, but not much, and usually more convenient). working around su www by putting your or its password in some file would seem far less secure. A script to invoke "rsync -avz --partial /some/path www@server:some/other/path" should be quick to write in python (although I do not python well).
1
0
0
I have a set of binary assets (swf files) each about 150Kb in size. I am developing them locally on my home computer and I want to periodically deploy them for review. My current strategy is: Copy the .swf's into a transfer directory that is also a hg (mercurial) repo. hg push the changes to my slicehost VPN ssh onto my slicehost VPN cd to my transfer directory and hg up su www and cp the changed files into my public folder for viewing. I would like to automate the process. Best case scenario is something close to: Copy the .swf's into a "quick deploy" directory Run a single local script to do all of the above. I am interested in: advice on where to put passwords since I need to su www to transfer files into the public web directories. how the division of responsibility between local machine and server is handled. I think using rsync is a better tool than hg since I don't really need a revision history of these types of changes. I can write this as a python script, a shell script or however is considered a best practice. Eventually I would like to build this into a system that can handle my modest deployment needs. Perhaps there is an open-source deployment system that handles this and other types of situations? I'll probably roll-my-own for this current need but long term I'd like something relatively flexible. Note: My home development computer is OS X and the target server is some recent flavour of Ubuntu. I'd prefer a python based solution but if this is best handled from the shell I have no problems putting it together that way.
How to deploy highly iterative updates
0.099668
0
0
349
2,085,430
2010-01-18T10:55:00.000
1
0
0
0
python,xml,database,sqlite,parsing
2,085,657
4
false
1
0
If you are accustomed to DOM (tree) access to xml from other language, you may find useful these standard library modules (and their respective docs): xml.dom xml.dom.minidom To save tha data to DB, you can use standard module sqlite3 or look for binding to mysql. Or you may wish to use something more abstract, like SQLAlchemy or Django's ORM.
1
7
0
I have a question related to some guidances to solve a problem. I have with me an xml file, I have to populate it into a database system (whatever, it might be sqlite, mysql) using scripting language: Python. Does anyone have any idea on how to proceed? Which technologies I need to read further? Which environments I have to install? Any tutorials on the same topic? I already tried to parse xml using both by tree-based and sax method in other language, but to start with Python, I don't know where to start. I already know how to design the database I need. Another question, is Python alone possible of executing database ddl queries?
populating data from xml file to a sqlite database using python
0.049958
1
0
15,042
2,086,016
2010-01-18T12:36:00.000
0
0
0
0
python,django,admin
2,094,101
2
true
1
0
It turns out it was a rather simple thing, I am just not experienced enough with Python and I was calling on my .NET experience. Bad mistake. I called project.settings.SETTING where I should have imported project.settings and then accessed settings.SETTING. In .NET the imports act just shortcuts so you don't have to type the whole 'path' to the function or setting, whereas in Python it seems that you must have the things you are using imported. I don't know if that makes any sense, or if it even correct, but it now works. Thanks for everyone's help, you are always a great help and I wouldn't be able to do this development and advance my knowledge without the resources here.
2
0
0
I have an issue where, when I log in to the Django admin site, I get a template syntax error in /Library/Python/2.6/site-packages/django/template/debug.py in render_node, line 81. I can't find out how to solve this as it is part of Django, I didn't write the code and I have no idea how it works. This did work fine up until a few days ago when I last tried it. The error is: Caught an exception while rendering: name 'pest' is not defined Where pest is the name of my project. As far as I know, I have all the apps in my project installed correctly. Thanks in advance!
Django Admin site TemplateSyntaxError at /admin/: name not defined
1.2
0
0
4,323
2,086,016
2010-01-18T12:36:00.000
1
0
0
0
python,django,admin
2,086,034
2
false
1
0
It seems like an error in the admin.py file for your app. It may be a missing import, or even a typo, but it's hard to tell without any code. It would be great if you could post your admin.py file so we can take a look. TemplateSyntaxErrors in Django are terrible, they almost never tell you what the real problem is. In this case, for example, the template is part of Django, but the error is probably something in your admin file, which Django reads to create the admin interface. The traceback is too deep to find out right away where in your code the problem is.
2
0
0
I have an issue where, when I log in to the Django admin site, I get a template syntax error in /Library/Python/2.6/site-packages/django/template/debug.py in render_node, line 81. I can't find out how to solve this as it is part of Django, I didn't write the code and I have no idea how it works. This did work fine up until a few days ago when I last tried it. The error is: Caught an exception while rendering: name 'pest' is not defined Where pest is the name of my project. As far as I know, I have all the apps in my project installed correctly. Thanks in advance!
Django Admin site TemplateSyntaxError at /admin/: name not defined
0.099668
0
0
4,323
2,086,961
2010-01-18T15:17:00.000
1
1
0
1
python,unix,terminal,cron
2,087,056
6
false
0
0
An easier workaround would be to pass a flag to the script only from the crontab, like --crontab, and then just check for that flag.
4
5
0
I would like to know how can I determine if a python script is executed from crontab? I don't want a solution that will require adding a parameter because I want to be able to detect this even from an imported module (not the main script).
How can I determine if a python script is executed from crontab?
0.033321
0
0
4,167
2,086,961
2010-01-18T15:17:00.000
0
1
0
1
python,unix,terminal,cron
2,087,816
6
false
0
0
If you want to detect this from an imported module, I would have the main program set a global variable in the module, which would output different things depending on the value of this global variable (and have the main program decide how to set the variable through a flag that you would use in your crontab). This is quite robust (comparing to studying PPIDs).
4
5
0
I would like to know how can I determine if a python script is executed from crontab? I don't want a solution that will require adding a parameter because I want to be able to detect this even from an imported module (not the main script).
How can I determine if a python script is executed from crontab?
0
0
0
4,167
2,086,961
2010-01-18T15:17:00.000
21
1
0
1
python,unix,terminal,cron
2,087,031
6
true
0
0
Not quite what you asked, but maybe what you want is os.isatty(sys.stdout.fileno()), which tells if stdout is connected to (roughly speaking) a terminal. It will be false if you pipe the output to a file or another process, or if the process is run from cron.
4
5
0
I would like to know how can I determine if a python script is executed from crontab? I don't want a solution that will require adding a parameter because I want to be able to detect this even from an imported module (not the main script).
How can I determine if a python script is executed from crontab?
1.2
0
0
4,167
2,086,961
2010-01-18T15:17:00.000
5
1
0
1
python,unix,terminal,cron
2,087,053
6
false
0
0
Set an environment variable at the cron command invocation. That works even within a module, as you can just check os.getenv().
4
5
0
I would like to know how can I determine if a python script is executed from crontab? I don't want a solution that will require adding a parameter because I want to be able to detect this even from an imported module (not the main script).
How can I determine if a python script is executed from crontab?
0.16514
0
0
4,167
2,087,148
2010-01-18T15:40:00.000
114
0
1
0
python,easy-install,pip
2,090,124
3
false
0
0
You can pip install a file perhaps by python setup.py sdist first. You can also pip install -e . which is like python setup.py develop.
1
153
0
python setup.py install will automatically install packages listed in requires=[] using easy_install. How do I get it to use pip instead?
Can I use `pip` instead of `easy_install` for `python setup.py install` dependency resolution?
1
0
0
113,410
2,087,492
2010-01-18T16:25:00.000
2
0
1
0
python,setuptools,distutils,easy-install,pip
2,087,761
4
false
0
0
If you really require an obscure version of another package, and there's no way to make do with other versions, you might want to simply distribute that version of the package with your own. If necessary put it in your own namespace to ensure that your version is the one that is used.
1
11
0
Some useful Python packages are broken on pypi, and the only acceptable version is a particular revision in a revision control system. Can that be expressed in setup.py e.g requires = 'svn://example.org/useful.package/trunk@1234' ?
Can a Python package depend on a specific version control revision of another Python package?
0.099668
0
0
3,935
2,087,920
2010-01-18T17:30:00.000
4
0
0
0
python,security
2,088,188
2
true
0
0
Your constraints set a very difficult problem: every user on the system must be able to access that password (since that's the only way for users to access that database)... yet they must not (except when running that script, and presumably only when running it without e.g. a python -i session that would let them set a breakpoint just before the connect call and look all through memory, so definitely able to look at the password). You could write a daemon process that runs as root (so can read mymodule.conf, which you'd make readable only by root) and accepts requests, somehow validates that the request comes from a "good" process (one that's running the exact module in question and not interactive), and only then supplies the password. That's fragile, mostly because of the need to determine whether a process may or may not have a breakpoint set at the crucial point of execution. Alternatively, you could further raise the technological stakes by having the daemon return, not the password, but rather the open socket ready to be wrapped in a DB-API compliant wrapper; some Unix systems allow open file descriptors to be sent between unrelated processes (a prereq for this approach) -- and of course you'd have to substantially rework the MySQL-based DB API to allow opening a connection around an already-open socket rather than a freshly made one. Note that a validated requesting process that happens to be interactive would still be able to get the connection object, once built, and send totally arbitrary requests -- they wouldn't be able to see the password, technically, but that's not much consolation. So it's unlikely that the large effort required here is warranted. So the next possible architecture is to mediate all db interaction via the validating daemon: a process would "log into" the daemon, get validated, and, if all's OK, gain a proxy connection to (e.g.) an XMLRPC server exposing the DB connection and functionality (the daemon would probably fork each such proxy process, right after reading the password from the root-only-readable file, and drop privileges immediately, just on general security ground). The plus wrt the previous alternative, in addition to probably easier implementation, is that the proxy would also get a look at every SQL request that's about to be sent to the MySQL db, and be able to validate and censor those requests as well (presumably on a default-deny basis, again for general security principles), thus seriously limiting the amount of damage a "rogue" client process (running interactively with a debugger) can do... one hopes;-). Yes, no easy solutions here -- but then, the problem your constraints pose is so far from easy that it borders on a self-contradictory impossibility;-). BTW, the problem's not particularly Python-related, it's essentially about choosing a secure architecture that comes close to "squaring the circle"-hard contradictory constraints on access permissions!-)
1
0
0
I have a written a Python module which due to its specifics needs to have a MySQL database connection. Right now, details of this connection (host, database, username and password to connect with) are stored in /etc/mymodule.conf in plaintext, which is obviously not a good idea. Supposedly, the /etc/mymodule.conf file is edited by the root user after the module is installed, since the module and its database may be used by all users of a Unix system. How should I securely store the password instead?
Storing system-wide DB connection password for a Python module
1.2
1
0
1,241
2,088,175
2010-01-18T18:13:00.000
1
0
0
0
event-handling,wxpython,wxwidgets
2,097,941
1
true
0
1
Even though you got your answer from the mailing list, we may as well replicate the answer here: Robin Dunn wrote: There isn't a way to access the event table currently, although I've often thought that it would be a good idea. Shame.
1
1
0
I have a wxPython window. How can I check its event handler table? (i.e. which handler is handling each event.)
Listing the event handlers for a wxPython window
1.2
0
0
230
2,089,635
2010-01-18T22:18:00.000
0
0
0
1
python,html,google-app-engine,mime-types
2,089,653
2
false
1
0
Setting a content-disposition: attachment header will cause most browsers to download whatever you send them as a file. Safari sometimes ignores it.
1
1
0
I have a python web-application running inside the Google App Engine. The application creates on user-demand a string and I want the string to be send to the browser client (application/octet-stream?) as a file. How can i realize this?
How to send a string from a python script at Google App Engine to the browser client as a file
0
0
0
180
2,089,998
2010-01-18T23:31:00.000
6
1
0
0
ironpython
2,090,745
3
false
1
1
You can provide a custom Stream or TextWriter which will be used for all output. You can provide those by using one of the ScriptRuntime.IO.SetOutput overloads. Your implementation of Stream or TextWriter should receive the strings and then output them to your editor window (potentially marshalling back onto the UI thread if you're running the script on a 2ndary execution thread).
1
4
0
We embed ironpython in our app sob that scripts can be executed in the context of our application. I use Python.CreateEngine() and ScriptScope.Execute() to execute python scripts. We have out own editor(written in C#) that can load ironpython scripts and run it. There are 2 problems I need to solve. If I have a print statement in ironpython script, how can i show it my editor(how will I tell python engine to redirect output to some handler in my C# code) I plan to use unittest.py for running unittest. When I run the following runner = unittest.TextTestRunner() runner.run(testsuite) the output is redirected to standard output but need a way for it to be redirected to my C# editor output window so that user can see the results. This question might be related to 1 Any help is appreciated G
Streaming Ironpython output to my editor
1
0
0
4,586
2,090,464
2010-01-19T01:25:00.000
1
0
0
0
python,windows
66,700,192
5
false
0
0
Pip install keyboard. Before you set foreground window, simulate a keyboard to esc that is keyboard.send('esc') You may want to do it three times for either of the following: Sidebar Windows key overlay Task manager which is always on top
1
28
0
How would I programmatically activate a window in Windows using Python? I'm sending keystrokes to it and at the moment I'm just making sure it's the last application used then sending the keystroke Alt+Tab to switch over to it from the DOS console. Is there a better way (since I've learned by experience that this way is by no means foolproof)?
Python Window Activation
0.039979
0
0
82,921
2,090,820
2010-01-19T03:15:00.000
7
0
1
0
python
2,090,825
8
false
0
0
The latest 2.6. Don't worry about 3.x; there isn't that much to learn.
5
21
0
If I'm absolutely new to Python and am literally reading about printing statements to console, variable types, collections, etc: What version of Python should I use? I'm aware that there is an abundance of 3rd party libraries for Python 2.6.x, but I'm scared I'll learn some things that won't carry over well into Python 3. For example, in Python 3 you can use input(), in Python 2 you have to use raw_input(). Thank you very much for the information.
What version of Python should I use if I'm a new to Python?
1
0
0
8,193
2,090,820
2010-01-19T03:15:00.000
1
0
1
0
python
2,091,413
8
false
0
0
#python IRC Channel says: It's too early to use Python 3.x If you are a beginner I would suggest start learning with Python 2.6
5
21
0
If I'm absolutely new to Python and am literally reading about printing statements to console, variable types, collections, etc: What version of Python should I use? I'm aware that there is an abundance of 3rd party libraries for Python 2.6.x, but I'm scared I'll learn some things that won't carry over well into Python 3. For example, in Python 3 you can use input(), in Python 2 you have to use raw_input(). Thank you very much for the information.
What version of Python should I use if I'm a new to Python?
0.024995
0
0
8,193
2,090,820
2010-01-19T03:15:00.000
1
0
1
0
python
2,098,857
8
false
0
0
Directly from python.org: If you don't know which version to use, start with Python 2.6.4; more existing third party software is compatible with Python 2 than Python 3 right now. If Guido is recommending it, I'd follow him :)
5
21
0
If I'm absolutely new to Python and am literally reading about printing statements to console, variable types, collections, etc: What version of Python should I use? I'm aware that there is an abundance of 3rd party libraries for Python 2.6.x, but I'm scared I'll learn some things that won't carry over well into Python 3. For example, in Python 3 you can use input(), in Python 2 you have to use raw_input(). Thank you very much for the information.
What version of Python should I use if I'm a new to Python?
0.024995
0
0
8,193
2,090,820
2010-01-19T03:15:00.000
17
0
1
0
python
2,090,843
8
true
0
0
Python 2.6 (and 2.5, 2.4) are what you will find installed on most machines (Linux) and what you will find most code written in. Therefore I'd start with Python 2.6.
5
21
0
If I'm absolutely new to Python and am literally reading about printing statements to console, variable types, collections, etc: What version of Python should I use? I'm aware that there is an abundance of 3rd party libraries for Python 2.6.x, but I'm scared I'll learn some things that won't carry over well into Python 3. For example, in Python 3 you can use input(), in Python 2 you have to use raw_input(). Thank you very much for the information.
What version of Python should I use if I'm a new to Python?
1.2
0
0
8,193
2,090,820
2010-01-19T03:15:00.000
13
0
1
0
python
2,090,836
8
false
0
0
It's really going to depend on what you want to do. Generally speaking Python 3 "isn't ready yet", in the sense that few libraries support Python 3. This will end up greatly limiting what you can accomplish with the language as a beginner. On the other hand, if you think you'll be spending your time on more "pure programming" tasks as you learn your way around, then Python 3 can be a good starting point, since things like strings are wildly different in Python 3. So, what do you want out of Python right now? Do you want to make useful things? Python 2.x. Do you want to learn about Python for the sake of learning about Python? Python 3. Here in a year or two, Python 3 will likely start being the default choice. Until then, it's really up to you. But you can be certain that whatever skills in Python you pick up are going to be useful in 2.x and 3. Some important things changed in Python 3, but Python 3 is still Python.
5
21
0
If I'm absolutely new to Python and am literally reading about printing statements to console, variable types, collections, etc: What version of Python should I use? I'm aware that there is an abundance of 3rd party libraries for Python 2.6.x, but I'm scared I'll learn some things that won't carry over well into Python 3. For example, in Python 3 you can use input(), in Python 2 you have to use raw_input(). Thank you very much for the information.
What version of Python should I use if I'm a new to Python?
1
0
0
8,193
2,090,950
2010-01-19T03:56:00.000
0
1
0
0
python,com
2,091,963
2
false
0
0
When doing python COM programming, I sometimes use VBA (in Excel) to test code that gives errors. That way, I can see if the problem is in the Python-COM layer, or if I get the same error when using VBA. I have sometimes seen that the error messages in VBA have descriptions that the Python exception lacks. VBA is quite nice for doing COM programming. You have tab completion/intellisense in the editor.
1
1
0
I've encountered the following error while scripting in Python. ERROR Tue 19. Jan 14:51:21 2010 C:\Python24\Lib\site-packages\win32com\client\util.py:0: Script Error com_error: (-2147217385, 'OLE error 0x80041017', None, None) Unfortunately, I don't know what it means, or even what other information I might need to find out. Does anyone have any insight into this?
unidentified com_error in python
0
0
0
1,265
2,091,097
2010-01-19T04:35:00.000
1
0
0
0
python,sockets,network-programming
2,091,157
3
false
0
0
I don't think there's any Python-specific limits. UDP packets have a theoretical limit of circa 65kb and TCP no upper limit, but you'll have flow control problems if you use packets much more than a few kilobytes.
1
6
0
i am new to network programming in python. I wanted to know that what is the maximum size packet we can transmit or receive on python socket? and how to find out it?
What is the maximum packet size a python socket can handle?
0.066568
0
1
7,528
2,091,294
2010-01-19T05:27:00.000
1
0
0
0
c++,python,django
2,091,309
4
false
1
0
You can use swig to create a C++ module that can be imported in python. An alternative is boost::python (but personnaly, I prefer swig).
1
4
0
I need to run a C++ Program from Django Framework. In a sense, I get inputs from UI in views.py . Once I have these inputs, I need to process the input using my C++ program and use those results. Is it possible ?
Run a C++ Program from Django Framework
0.049958
0
0
4,911
2,091,508
2010-01-19T06:17:00.000
2
0
1
0
python,performance
2,091,858
3
false
0
0
PyStone is not a good or reliable benchmark, so you should probably not interpret them at all. But, no, higher is better, not the other way around. Also be sure to run it multiple times after each other, many CPU's slow down when idle today.
2
4
0
I have three different laptops with Python2.5 on it. If I run Pystone I get essentially the same values. Intel Pentium M @1.80GHz - 1.5GB RAM Intel T2300 @1.66GHz - 1GB RAM Intel Pentium Dual T2370 @1.73Ghz - 2GB RAM These are their respective Pystone values: 45787 pystones/second 44377 pystones/second 43861 pystones/second I don't think less is better but my oldest machine scores higher and the most recent scores the lowest. Why would this happen?
How should you interpret the PyStone value across machines?
0.132549
0
0
7,959
2,091,508
2010-01-19T06:17:00.000
1
0
1
0
python,performance
22,354,756
3
false
0
0
pystones is a benchmark, but it's not a benchmark of the underlying hardware, is meant more as a benchmark to compare python implementations. That being so, comparing pystones on different hardware makes not much sense.
2
4
0
I have three different laptops with Python2.5 on it. If I run Pystone I get essentially the same values. Intel Pentium M @1.80GHz - 1.5GB RAM Intel T2300 @1.66GHz - 1GB RAM Intel Pentium Dual T2370 @1.73Ghz - 2GB RAM These are their respective Pystone values: 45787 pystones/second 44377 pystones/second 43861 pystones/second I don't think less is better but my oldest machine scores higher and the most recent scores the lowest. Why would this happen?
How should you interpret the PyStone value across machines?
0.066568
0
0
7,959
2,093,411
2010-01-19T12:28:00.000
2
0
1
1
c++,python
2,093,422
4
false
0
0
one dirty method: You can use Python to read (raw_input) from stdin (if there is not input, it will wait). the C++ program writes to stdout.
2
1
0
I am writing a module in Python which runs a C++ Program using subprocess module. Once I get the output from C++, I need to store the that in Python List . How do I do that ?
C++ I/O with Python
0.099668
0
0
1,539
2,093,411
2010-01-19T12:28:00.000
0
0
1
1
c++,python
2,093,491
4
false
0
0
In the command for the process you could do a redirect to a temporary file. Then read that file when the process returns.
2
1
0
I am writing a module in Python which runs a C++ Program using subprocess module. Once I get the output from C++, I need to store the that in Python List . How do I do that ?
C++ I/O with Python
0
0
0
1,539
2,093,822
2010-01-19T13:37:00.000
1
0
0
0
python,django,performance,chat,private-messaging
2,094,368
6
false
1
0
I think for a chat application you can use other technologies, such as AMQP(RabbitMQ, etc), Comet, etc. But, for develop user profile, PMs, and other you can use Django. Do not forget that performance still depends on server configuration (web server software, cache, db)
1
10
0
If i devlop a chat application using django will it have some performance problem? Can i do server push in django? I want to have PM and room discussions as well.
Chat application using django
0.033321
0
0
12,068
2,093,837
2010-01-19T13:40:00.000
0
1
1
1
python,automator
2,094,638
2
false
0
0
When you install modules, you typically install them per Python instance. So in this case you have installed them for the Python in /Library/Frameworks/Python.framework/Versions/Current/bin/python, and it will then be available only for that Python. /usr/bin/python is then apparently another Python installation (I'm not an OS X expert). To make it available for the /usr/bin/python installation, install it for /usr/bin/python.
1
2
0
I have installed Py-Appscript on my machine and it can be used with the Python installation at /Library/Frameworks/Python.framework/Versions/Current/bin/python. I am trying to use this installation of Py-Appscript with an Automator service. To do this, I use the Run Shell Script action and then set the Shell to usr/bin/python (which is my only choice for Python, unfortunately). The usr/bin/python does not appear to have access to my third-party modules and crashes on the line: from appscript import * Is there a way for me to give usr/bin/python access to my third-party modules? OR Is there a way to tell Automator to use /Library/Frameworks/Python.framework/Versions/Current/bin/python instead? I need Automator to run the Python directly from the Run Shell Script action. Any action that calls Python scripts that are external to Automator (via bin/bash, for example) does not perform quickly enough to be useful.
Using Third-Party Modules with Python in an Automator Service
0
0
0
2,403
2,095,505
2010-01-19T17:28:00.000
-1
0
1
0
python,import
2,097,024
6
false
1
0
Might not be relevant, but have you considered using imdbpy? Last time I used it it worked pretty well...
1
2
0
I just downloaded Beautiful Soup and I've decided I'll make a small library (is that what they call them in Python?) that will return results of a movie given and IMDB movie search. My question is, how exactly does this import thing work? For example, I downloaded BeautifulSoup and all it is, is a .py file. Does that file have to be in the same folder as the my python application (my project that will use the library)?
A few questions regarding Pythons 'import' feature
-0.033321
0
1
217
2,096,000
2010-01-19T18:31:00.000
7
0
0
0
python,ide,intellisense,geany
2,096,071
2
true
0
0
No, because is Python is dynamically typed language and quite hard to achieve that. Python plugins for netbeans do that partially, but I believe such plugin is not in geany developers plans. There are different things to be done ;-) However, geany provides some completions support. First, it analyzes your imports in a file and uses it in completions; furthermore it completes functions from the std library. It also analyzes all you open files for suggestions, although you may need to apply it in preferences. Also you can get call tips, when you hit Ctrl+Shift+Space, which not everyone know about. They are quite good, because they appear in form <Class>.<method>(<args>), which is very helpful.
1
10
0
In visual studio, I could just press ctrl+spacekey and the methods appeared. In Geany is there a way for me to get this functionality?
How can I get Geany to show me the methods a library has when I press the '.' key?
1.2
0
0
8,191
2,096,334
2010-01-19T19:19:00.000
9
1
1
0
python,c,optimization
2,096,358
5
false
0
1
First measure then optimize
1
4
0
In a game that I am writing, I use a 2D vector class which I have written to handle the speeds of the objects. This is called a large number of times every frame as there are a lot of objects on the screen, so any increase I can make in its speed will be useful. It is pretty simple, consisting mostly of wrappers to the related math functions. It would be quite trivial to rewrite in C, but I am not sure whether doing so will make any significant difference as all it really does is call the underlying math functions, add, multiply or divide. So, my question is under what circumstances does it make sense to rewrite in C? Where will you see a significant speed boost, and where can you see a reasonable speed boost without rewriting an extensive amount of the program?
When Does It Make Sense To Rewrite A Python Module in C?
1
0
0
429
2,097,134
2010-01-19T21:13:00.000
1
0
1
1
python,ide
2,111,703
6
false
0
0
I am also working with mod_wsgi, python, apache software stack. I am using WingIDE as my environment, which gives you debugging capabilities. If you are vi person it has a VI/VIM personality which coupled with auto-completion makes for a very productive work environment.
4
2
0
Would like to know what is the best F/OSS IDE for Python Web development. I've always used vim myself, but I'm increasingly interested in having a tool that integrates syntax checking/highlighting, source control, debugging, and other IDE goodies. I use both Windows and Linux as desktops, so recommendations for either platform are welcome! Thanks, -aj
Best F/OSS IDE for Python Web Development (Windows or Linux)?
0.033321
0
0
1,183
2,097,134
2010-01-19T21:13:00.000
0
0
1
1
python,ide
2,120,061
6
false
0
0
What about IDLE? It's bundled with Python distributions.
4
2
0
Would like to know what is the best F/OSS IDE for Python Web development. I've always used vim myself, but I'm increasingly interested in having a tool that integrates syntax checking/highlighting, source control, debugging, and other IDE goodies. I use both Windows and Linux as desktops, so recommendations for either platform are welcome! Thanks, -aj
Best F/OSS IDE for Python Web Development (Windows or Linux)?
0
0
0
1,183
2,097,134
2010-01-19T21:13:00.000
0
0
1
1
python,ide
2,120,241
6
false
0
0
"syntax checking/highlighting, source control, debugging, and other IDE goodies" Emacs fits this criteria, if you use the right extensions. Though it does have a much steeper learning curve than any IDE I know of.
4
2
0
Would like to know what is the best F/OSS IDE for Python Web development. I've always used vim myself, but I'm increasingly interested in having a tool that integrates syntax checking/highlighting, source control, debugging, and other IDE goodies. I use both Windows and Linux as desktops, so recommendations for either platform are welcome! Thanks, -aj
Best F/OSS IDE for Python Web Development (Windows or Linux)?
0
0
0
1,183
2,097,134
2010-01-19T21:13:00.000
0
0
1
1
python,ide
2,120,215
6
false
0
0
I've been using Komodo Edit for a while now and it's quite good for Python development. It's free and I think it's also open-source now, though it wasn't always so.
4
2
0
Would like to know what is the best F/OSS IDE for Python Web development. I've always used vim myself, but I'm increasingly interested in having a tool that integrates syntax checking/highlighting, source control, debugging, and other IDE goodies. I use both Windows and Linux as desktops, so recommendations for either platform are welcome! Thanks, -aj
Best F/OSS IDE for Python Web Development (Windows or Linux)?
0
0
0
1,183
2,097,556
2010-01-19T22:12:00.000
0
0
0
0
python,html,forms,pylons
2,500,262
2
false
1
0
Yes (to iterate Tom's answer), HTML is designed to explicitly only allow a single form to be submitted at a time. Plus, forms may not be nested, so no confusion possible there. However, a single form may contain multiple submit buttons. So, you may if you really want to organize your page as one big single form, and so submitting will submit all the values each time. You will need to take care then that there are all field names are distinct -- so, not convenient if you have a repetition of "item" forms, in which case it should be a lot cleaner to have a form per item...
2
1
0
I've got a web page I'm generating with Pylons and the evoque templating tool. I'm trying to generate a page with multiple forms per page (one form is part of a base template that becomes part of every page). I'm having a problem as I seemingly can only get the form element values for one form; whenever I try to get the value from the base template, I get nothing back. Is there a way in Pylons to get a form element from a form by name? I'm using the request.params("variable_name") style that is standard in Pylons. Thanks in advance for your help! Doug
Pylons and multiple forms per page
0
0
0
255
2,097,556
2010-01-19T22:12:00.000
1
0
0
0
python,html,forms,pylons
2,104,760
2
false
1
0
You will only get the form values for the form that was posted in the request(ie: whichever submit button the user clicked), that's how html works.
2
1
0
I've got a web page I'm generating with Pylons and the evoque templating tool. I'm trying to generate a page with multiple forms per page (one form is part of a base template that becomes part of every page). I'm having a problem as I seemingly can only get the form element values for one form; whenever I try to get the value from the base template, I get nothing back. Is there a way in Pylons to get a form element from a form by name? I'm using the request.params("variable_name") style that is standard in Pylons. Thanks in advance for your help! Doug
Pylons and multiple forms per page
0.099668
0
0
255
2,098,088
2010-01-19T23:49:00.000
33
0
1
0
python
2,098,096
6
true
0
0
No. Typical Python style is to put related classes in the same module. It may be that a class ends up in a module of its own (especially if it's a large class), but it should not be a goal in its own right. And when you do, please do not name the module after the class -- you'll just end up confusing yourself and others about which is which.
4
40
0
I'm quite new to Python in general. I'm aware that I can create multiple classes in the same .py file, but I'm wondering if I should create each class in its own .py file. In C# for instance, I would have a class that handles all Database interactions. Then another class that had the business rules. Is this the case in Python?
Should I create each class in its own .py file?
1.2
0
0
22,009
2,098,088
2010-01-19T23:49:00.000
7
0
1
0
python
4,672,452
6
false
0
0
I'll disagree with the others and say yes. For me, I have had better success putting each class in its own file (module). But there are exceptions so let me explain with an example. If you have a class Foo, then put it in a file called Foo.py, with the following sections: Imports This is where you pull in dependencies. Examples: import math, from Bar import * Globals This is where you define the external interface to your module, which are all of the symbols that are visible outside of this module. Example: __all__ = ['Foo'] This is also where you can define global variables (bad) and global constants (good). These globals need not be exported; they can be made global merely to simplify the code. Example: PI = 3.14159 means that you can write PI, whereas if you defined it inside class Foo then you would need to write Foo.PI. Functions This is where you define all top-level functions that are relevant to class Foo, but don't belong in the class Foo namespace. These are probably rare since classes allow both @staticmethods and inner classes. Example: def print_foo(foo): print(foo) Classes Example: class Foo(object): pass Sometimes you will want to place more than one class in the same module. You should do this whenever two or more classes are conceptually related to the point where you would almost always use them together and never independently. This is the exception, not the norm. In this case add all of the class names to the __all__ global. Finally, for every module Foo.py, there should be a corresponding unit test module called testFoo.py.
4
40
0
I'm quite new to Python in general. I'm aware that I can create multiple classes in the same .py file, but I'm wondering if I should create each class in its own .py file. In C# for instance, I would have a class that handles all Database interactions. Then another class that had the business rules. Is this the case in Python?
Should I create each class in its own .py file?
1
0
0
22,009