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
189,943
2008-10-10T02:39:00.000
82
0
1
0
python,image-processing,background-subtraction,image-comparison,timelapse
189,960
24
false
0
0
A simple solution: Encode the image as a jpeg and look for a substantial change in filesize. I've implemented something similar with video thumbnails, and had a lot of success and scalability.
6
212
0
Here's what I would like to do: I'm taking pictures with a webcam at regular intervals. Sort of like a time lapse thing. However, if nothing has really changed, that is, the picture pretty much looks the same, I don't want to store the latest snapshot. I imagine there's some way of quantifying the difference, and I would have to empirically determine a threshold. I'm looking for simplicity rather than perfection. I'm using python.
How can I quantify difference between two images?
1
0
0
231,920
189,943
2008-10-10T02:39:00.000
14
0
1
0
python,image-processing,background-subtraction,image-comparison,timelapse
190,036
24
false
0
0
A trivial thing to try: Resample both images to small thumbnails (e.g. 64 x 64) and compare the thumbnails pixel-by-pixel with a certain threshold. If the original images are almost the same, the resampled thumbnails will be very similar or even exactly the same. This method takes care of noise that can occur especially in low-light scenes. It may even be better if you go grayscale.
6
212
0
Here's what I would like to do: I'm taking pictures with a webcam at regular intervals. Sort of like a time lapse thing. However, if nothing has really changed, that is, the picture pretty much looks the same, I don't want to store the latest snapshot. I imagine there's some way of quantifying the difference, and I would have to empirically determine a threshold. I'm looking for simplicity rather than perfection. I'm using python.
How can I quantify difference between two images?
1
0
0
231,920
190,115
2008-10-10T04:19:00.000
0
0
1
0
python,python-3.x,python-idle
56,122,726
3
false
0
0
Not really. You can download the latest version of Python 3.x suitable for whichever operating system you are using, and you can load IDLE without any internet.
1
1
0
If I have no connection to internet, does that mean I can't start IDLE (which comes with python 3.0)?
IDLE doesn't start in python 3.0
0
0
1
945
190,675
2008-10-10T09:56:00.000
0
0
1
1
python,google-app-engine,image,analysis
190,958
3
false
0
0
If you are willing to put Flash or a Java applet on the page, you might be able to do it on the client. I'm not sure if anything like canvas or SVG supports pixel-level manipulation, but if they do, you might be able to get it to work in some browsers with JavaScript. The Flash or Java Applet, can be invisible and optional -- you can use JavaScript to detect if the user has the plugin and only support this feature when they do.
1
1
0
How can I read the colors of an image with python using google app engine? Example: I like to build a function to determine the most striking colors of an image to set a harmonic background color for it.
Read colors of image with Python (GAE)
0
0
0
1,703
191,062
2008-10-10T12:40:00.000
7
0
0
0
python,pylons,cherrypy,web-frameworks,turbogears
191,805
5
false
1
0
Give a try to web2py. It is point and click (you do not even need to install Python, comes with it). You develop using a web interface and you can deploy almost everywhere, including iPhone, Oracle and Google App Engine. Before trying web2py, try install some of the other Python frameworks, you will appreciate it even more.
2
10
0
Could someone please explain to me how the current python webframworks fit together? The three I've heard of are CherryPy, TurboGears and Pylons. However I'm confused because TurboGears seems to use CherryPy as the 'Controller' (although isn't CherryPy a framework in in it's own right?), and TurbGears 2 is going to be built on top of Pylons (which I thought did the same thing?).
Python Webframework Confusion
1
0
0
2,552
191,062
2008-10-10T12:40:00.000
6
0
0
0
python,pylons,cherrypy,web-frameworks,turbogears
191,336
5
false
1
0
CherryPy is not a full-stack web framework (like Django for example), in fact it isn't a web framework but a HTTP framework. Writing a web application using CherryPy is much like writing a regular object-oriented application in Python. Also, CherryPy has it's own production-ready WSGI web server, which can be also used for applications written using other frameworks, hence the confusion surrounding CherryPy as a framework.
2
10
0
Could someone please explain to me how the current python webframworks fit together? The three I've heard of are CherryPy, TurboGears and Pylons. However I'm confused because TurboGears seems to use CherryPy as the 'Controller' (although isn't CherryPy a framework in in it's own right?), and TurbGears 2 is going to be built on top of Pylons (which I thought did the same thing?).
Python Webframework Confusion
1
0
0
2,552
191,700
2008-10-10T14:52:00.000
2
0
1
1
python,memory
191,790
2
false
0
0
Are you sure that the machine does not have a 128M process limit? If you are running the python script as a CGI inside a web server, it is quite likely that there is a process limit set - you will need to look at the web server configuration.
2
2
0
I am new to python and struggling to find how to control the amount of memory a python process can take? I am running python on a Cento OS machine with more than 2 GB of main memory size. Python is taking up only 128mb of this and I want to allocate it more. I tried to search all over the internet on this for last half an hour and found absolutely nothing! Why is it so difficult to find information on python related stuff :( I would be happy if someone could throw some light on how to configure python for various things like allowed memory size, number of threads etc. A link to a site where most controllable parameters of python are described would be appreciated well.
Configuring python
0.197375
0
0
1,627
191,700
2008-10-10T14:52:00.000
11
0
1
1
python,memory
191,744
2
true
0
0
Forget all that, python just allocates more memory as needed, there is not a myriad of comandline arguments for the VM as in java, just let it run. For all comandline switches you can just run python -h or read man python.
2
2
0
I am new to python and struggling to find how to control the amount of memory a python process can take? I am running python on a Cento OS machine with more than 2 GB of main memory size. Python is taking up only 128mb of this and I want to allocate it more. I tried to search all over the internet on this for last half an hour and found absolutely nothing! Why is it so difficult to find information on python related stuff :( I would be happy if someone could throw some light on how to configure python for various things like allowed memory size, number of threads etc. A link to a site where most controllable parameters of python are described would be appreciated well.
Configuring python
1.2
0
0
1,627
192,907
2008-10-10T20:22:00.000
7
0
0
0
python,xml,dom,sax,elementtree
192,913
4
false
0
0
ElementTree's parse() is like DOM, whereas iterparse() is like SAX. In my opinion, ElementTree is better than DOM and SAX in that it provides API easier to work with.
1
80
0
Python has several ways to parse XML... I understand the very basics of parsing with SAX. It functions as a stream parser, with an event-driven API. I understand the DOM parser also. It reads the XML into memory and converts it to objects that can be accessed with Python. Generally speaking, it was easy to choose between the two depending on what you needed to do, memory constraints, performance, etc. (Hopefully I'm correct so far.) Since Python 2.5, we also have ElementTree. How does this compare to DOM and SAX? Which is it more similar to? Why is it better than the previous parsers?
XML parsing - ElementTree vs SAX and DOM
1
0
1
33,129
193,077
2008-10-10T21:26:00.000
23
0
0
1
python,linux
193,963
8
false
0
0
Create a deb (for everything Debian-derived) and an rpm (for Fedora/SuSE). Add the right dependencies to the packaging and you can be reasonably sure that it will work.
3
33
0
How can I distribute a standalone Python application in Linux? I think I can take for granted the presence of a recent Python interpreter in any modern distribution. The problem is dealing with those libraries that do not belong to the standard library, i.e. wxPython, scipy, python cryptographic toolkit, reportlab, and so on. Is there a working Linux counterpart to, say, py2exe (which, by the way, I have never tried)? Is there a free, opensource one?
Standalone Python applications in Linux
1
0
0
28,132
193,077
2008-10-10T21:26:00.000
-9
0
0
1
python,linux
193,083
8
false
0
0
Nope. Python is notoriously flaky with respect to different setups. The only sane way to deploy a python app is to ship the whole bundle of interpreter and libraries that you are relying on with your code. That will most likely work. Update 2019: I stand by this. Virtualenv is a way of packaging libraries and interpreters together. Tox is a testing tool to test that interpreter/dependency matrix. Docker is a widely used way of then deploying the bundle.
3
33
0
How can I distribute a standalone Python application in Linux? I think I can take for granted the presence of a recent Python interpreter in any modern distribution. The problem is dealing with those libraries that do not belong to the standard library, i.e. wxPython, scipy, python cryptographic toolkit, reportlab, and so on. Is there a working Linux counterpart to, say, py2exe (which, by the way, I have never tried)? Is there a free, opensource one?
Standalone Python applications in Linux
-1
0
0
28,132
193,077
2008-10-10T21:26:00.000
7
0
0
1
python,linux
193,101
8
false
0
0
You can't easily do it in a distribution-neutral format. The only reliable dependency tracking mechanisms are built into the package management systems on the distributions and will vary from distribution to distribution. You'll effectively have to do rpm for fedora, debs for ubuntu and debian etc. Py2exe works fine on Windows. It builds a distribution with all of the necessary DLL's and a wrapper for the python interpreter that starts your program. It's fairly straightforward to install - just drop it in a directory - so making a msi file for it is trivial.
3
33
0
How can I distribute a standalone Python application in Linux? I think I can take for granted the presence of a recent Python interpreter in any modern distribution. The problem is dealing with those libraries that do not belong to the standard library, i.e. wxPython, scipy, python cryptographic toolkit, reportlab, and so on. Is there a working Linux counterpart to, say, py2exe (which, by the way, I have never tried)? Is there a free, opensource one?
Standalone Python applications in Linux
1
0
0
28,132
193,161
2008-10-10T21:50:00.000
18
0
1
1
python,directory-structure,organization,project-structure
193,280
8
false
0
0
In my experience, it's just a matter of iteration. Put your data and code wherever you think they go. Chances are, you'll be wrong anyway. But once you get a better idea of exactly how things are going to shape up, you're in a much better position to make these kinds of guesses. As far as extension sources, we have a Code directory under trunk that contains a directory for python and a directory for various other languages. Personally, I'm more inclined to try putting any extension code into its own repository next time around. With that said, I go back to my initial point: don't make too big a deal out of it. Put it somewhere that seems to work for you. If you find something that doesn't work, it can (and should) be changed.
3
880
0
Imagine that you want to develop a non-trivial end-user desktop (not web) application in Python. What is the best way to structure the project's folder hierarchy? Desirable features are ease of maintenance, IDE-friendliness, suitability for source control branching/merging, and easy generation of install packages. In particular: Where do you put the source? Where do you put application startup scripts? Where do you put the IDE project cruft? Where do you put the unit/acceptance tests? Where do you put non-Python data such as config files? Where do you put non-Python sources such as C++ for pyd/so binary extension modules?
What is the best project structure for a Python application?
1
0
0
551,755
193,161
2008-10-10T21:50:00.000
470
0
1
1
python,directory-structure,organization,project-structure
193,181
8
true
0
0
Doesn't too much matter. Whatever makes you happy will work. There aren't a lot of silly rules because Python projects can be simple. /scripts or /bin for that kind of command-line interface stuff /tests for your tests /lib for your C-language libraries /doc for most documentation /apidoc for the Epydoc-generated API docs. And the top-level directory can contain README's, Config's and whatnot. The hard choice is whether or not to use a /src tree. Python doesn't have a distinction between /src, /lib, and /bin like Java or C has. Since a top-level /src directory is seen by some as meaningless, your top-level directory can be the top-level architecture of your application. /foo /bar /baz I recommend putting all of this under the "name-of-my-product" directory. So, if you're writing an application named quux, the directory that contains all this stuff is named /quux. Another project's PYTHONPATH, then, can include /path/to/quux/foo to reuse the QUUX.foo module. In my case, since I use Komodo Edit, my IDE cuft is a single .KPF file. I actually put that in the top-level /quux directory, and omit adding it to SVN.
3
880
0
Imagine that you want to develop a non-trivial end-user desktop (not web) application in Python. What is the best way to structure the project's folder hierarchy? Desirable features are ease of maintenance, IDE-friendliness, suitability for source control branching/merging, and easy generation of install packages. In particular: Where do you put the source? Where do you put application startup scripts? Where do you put the IDE project cruft? Where do you put the unit/acceptance tests? Where do you put non-Python data such as config files? Where do you put non-Python sources such as C++ for pyd/so binary extension modules?
What is the best project structure for a Python application?
1.2
0
0
551,755
193,161
2008-10-10T21:50:00.000
13
0
1
1
python,directory-structure,organization,project-structure
193,256
8
false
0
0
Non-python data is best bundled inside your Python modules using the package_data support in setuptools. One thing I strongly recommend is using namespace packages to create shared namespaces which multiple projects can use -- much like the Java convention of putting packages in com.yourcompany.yourproject (and being able to have a shared com.yourcompany.utils namespace). Re branching and merging, if you use a good enough source control system it will handle merges even through renames; Bazaar is particularly good at this. Contrary to some other answers here, I'm +1 on having a src directory top-level (with doc and test directories alongside). Specific conventions for documentation directory trees will vary depending on what you're using; Sphinx, for instance, has its own conventions which its quickstart tool supports. Please, please leverage setuptools and pkg_resources; this makes it much easier for other projects to rely on specific versions of your code (and for multiple versions to be simultaneously installed with different non-code files, if you're using package_data).
3
880
0
Imagine that you want to develop a non-trivial end-user desktop (not web) application in Python. What is the best way to structure the project's folder hierarchy? Desirable features are ease of maintenance, IDE-friendliness, suitability for source control branching/merging, and easy generation of install packages. In particular: Where do you put the source? Where do you put application startup scripts? Where do you put the IDE project cruft? Where do you put the unit/acceptance tests? Where do you put non-Python data such as config files? Where do you put non-Python sources such as C++ for pyd/so binary extension modules?
What is the best project structure for a Python application?
1
0
0
551,755
193,701
2008-10-11T05:34:00.000
2
0
1
0
php,python,api,rest
193,807
6
false
0
0
Try to write a common unit test suite for both. Maybe by wrapping a class in one language for calling it from the other. If you can't do it, at least make sure the two versions of the tests are equivalent.
6
3
0
I am working on developing a pair of libraries to work with a REST API. Because I need to be able to use the API in very different settings I'm currently planning to have a version in PHP (for web applications) and a second version in Python (for desktop applications, and long running processes). Are there any best practices to follow in the development of the libraries to help maintain my own sanity?
What are best practices for developing consistent libraries?
0.066568
0
0
493
193,701
2008-10-11T05:34:00.000
2
0
1
0
php,python,api,rest
193,714
6
false
0
0
'Be your own client' : I've found that the technique of writing tests first is an excellent way of ensuring an API is easy to use. Writing tests first means you will be thinking like a 'consumer' of your API rather than just an implementor.
6
3
0
I am working on developing a pair of libraries to work with a REST API. Because I need to be able to use the API in very different settings I'm currently planning to have a version in PHP (for web applications) and a second version in Python (for desktop applications, and long running processes). Are there any best practices to follow in the development of the libraries to help maintain my own sanity?
What are best practices for developing consistent libraries?
0.066568
0
0
493
193,701
2008-10-11T05:34:00.000
0
0
1
0
php,python,api,rest
389,024
6
false
0
0
AFAIKT there are a lot of bridges from to scripting languages. Let's take e.g Jruby, it's Ruby + Java, then there are things to embed Ruby in Python (or the other way). Then there are examples like Etoile where the base is Objective-C but also bridges to Python and Smalltalk, another approach on wide use: Wrapping C libraries, examples are libxml2, libcurl etc etc. Maybe this could be the base. Let's say your write all for Python but do implement a bridge to PHP. So you do not have that much parrallel development. Or maybe it's not the worst idea to base that stuff let's say on .NET, then you suddenly have a whole bunch of languages to your disposal which in principal should be usable from every other language on the .NET platform.
6
3
0
I am working on developing a pair of libraries to work with a REST API. Because I need to be able to use the API in very different settings I'm currently planning to have a version in PHP (for web applications) and a second version in Python (for desktop applications, and long running processes). Are there any best practices to follow in the development of the libraries to help maintain my own sanity?
What are best practices for developing consistent libraries?
0
0
0
493
193,701
2008-10-11T05:34:00.000
0
0
1
0
php,python,api,rest
193,709
6
false
0
0
Well, the obvious one would be to keep your naming consistent. Functions and classes should be named similarly (if not identically) in both implementations. This usually happens naturally whenever you implement an API separately in two different languages. The big ticket item though (at least in my book) is to follow language-specific idioms. For example, let's assume that I were implementing a REST API in two languages I'm more familiar with: Ruby and Scala. The Ruby version might have a class MyCompany::Foo which contains method bar_baz(). Conversely, the Scala version of the same API would have a class com.mycompany.rest.Foo with a method barBaz(). It's just naming conventions, but I find it goes a long way to helping your API to feel "at home" in a particular language, even when the design was created elsewhere. Beyond that I have only one piece of advise: document, document, document. That's easily the best way to keep your sanity when dealing with a multi-implementation API spec.
6
3
0
I am working on developing a pair of libraries to work with a REST API. Because I need to be able to use the API in very different settings I'm currently planning to have a version in PHP (for web applications) and a second version in Python (for desktop applications, and long running processes). Are there any best practices to follow in the development of the libraries to help maintain my own sanity?
What are best practices for developing consistent libraries?
0
0
0
493
193,701
2008-10-11T05:34:00.000
6
0
1
0
php,python,api,rest
193,713
6
true
0
0
So, the problem with developing parallel libraries in different languages is that often times different languages will have different idioms for the same task. I know this from personal experience, having ported a library from Python to PHP. Idioms aren't just naming: for example, Python has a good deal of magic you can use with getters and setters to make object properties act magical; Python has monkeypatching; Python has named parameters. With a port, you want to pick a "base" language, and then attempt to mimic all the idioms in the other language (not easy to do); for parallel development, not doing anything too tricky and catering to the least common denominator is preferable. Then bolt on the syntax sugar.
6
3
0
I am working on developing a pair of libraries to work with a REST API. Because I need to be able to use the API in very different settings I'm currently planning to have a version in PHP (for web applications) and a second version in Python (for desktop applications, and long running processes). Are there any best practices to follow in the development of the libraries to help maintain my own sanity?
What are best practices for developing consistent libraries?
1.2
0
0
493
193,701
2008-10-11T05:34:00.000
0
0
1
0
php,python,api,rest
959,080
6
false
0
0
why not use python for web applications too? there are several frameworks available: django, web2py - similar to django but many say it's simpler to use, there is also TurboGears, web.py, Pylons along the lines of bridging - you could use interprocess communication to have PHP and python application (in daemon mode) talk to each other.
6
3
0
I am working on developing a pair of libraries to work with a REST API. Because I need to be able to use the API in very different settings I'm currently planning to have a version in PHP (for web applications) and a second version in Python (for desktop applications, and long running processes). Are there any best practices to follow in the development of the libraries to help maintain my own sanity?
What are best practices for developing consistent libraries?
0
0
0
493
193,789
2008-10-11T07:06:00.000
4
0
1
0
python,windows,microphone
193,823
3
true
0
0
Best way to go about it would be to use the ctypes library and use WinMM from that. mixerOpen will open a microphone device and you can read the data easily from there. Should be very straightforward.
1
10
0
Can I access a users microphone in Python? Sorry I forgot not everyone is a mind reader: Windows at minimum XP but Vista support would be VERY good.
Microphone access in Python
1.2
0
0
11,203
193,862
2008-10-11T08:44:00.000
1
1
1
0
ironpython,boo
194,040
7
false
0
0
I agree with VolkA here. Being able to run Django is big. It's just such an amazing framework, that Boo will have a hard time redoing it. Today it's more a question of the frameworks that a language provides, than it is the construct that it provides. And Boo doesn't provide much improvements over Python in the constructs it support.
2
26
0
After having looked at each of these two projects, it seems that both are VERY similar. Both run on top of the CLI, both have python style syntax, both use .NET instead of the standard python libraries. So, what are the differences between them and advantages of each?
Boo vs. IronPython
0.028564
0
0
6,385
193,862
2008-10-11T08:44:00.000
4
1
1
0
ironpython,boo
199,236
7
false
0
0
I have written applications in both Boo and IronPython. For me IronPython has been the more robust choice and much of what I've written in CPython ports without changes. All recent projects have been pure IronPython if targeted for .Net Framework. Since Jim "defected" to Microsoft, IronPython has been elevated to a top tier language. There's even Visual Studio for it.
2
26
0
After having looked at each of these two projects, it seems that both are VERY similar. Both run on top of the CLI, both have python style syntax, both use .NET instead of the standard python libraries. So, what are the differences between them and advantages of each?
Boo vs. IronPython
0.113791
0
0
6,385
194,289
2008-10-11T16:34:00.000
4
0
0
0
c#,java,python,chess,dataformat
194,306
9
false
0
0
Let's think. We're describing objects (locations and pieces) with states and behaviors. We need to note a current state and an ever-changing set of allowed state changes from a current state. This is programming. You don't want some "meta-language" that you can then parse in a regular programming language. Just use a programming language. Start with ordinary class definitions in an ordinary language. Get it all to work. Then, those class definitions are the definition of chess. With only miniscule exceptions, all programming languages are Textual Human readable Reasonably standardized Easily parsed by their respective compilers or interpreters. Just pick a language, and you're done. Since it will take a while to work out the nuances, you'll probably be happier with a dynamic language like Python or Ruby than with a static language like Java or C#. If you want portability. Pick a portable language. If you want the language embedded in a "larger" application, then, pick the language for your "larger" application. Since the original requirements were incomplete, a secondary minor issue is how to have code that runs in conjunction with multiple clients. Don't have clients in multiple languages. Pick one. Java, for example, and stick with it. If you must have clients in multiple languages, then you need a language you can embed in all three language run-time environments. You have two choices. Embed an interpreter. For example Python, Tcl and JavaScript are lightweight interpreters that you can call from C or C# programs. This approach works for browsers, it can work for you. Java, via JNI can make use of this, also. There are BPEL rules engines that you can try this with. Spawn an interpreter as a separate subprocess. Open a named pipe or socket or something between your app and your spawned interpreter. Your Java and C# clients can talk with a Python subprocess. Your Python server can simply use this code.
4
8
0
I'm going to be writing a chess server and one or more clients for chess and I want to describe the rules of chess (e.g. allowable moves based on game state, rules for when a game is complete) in a programming language independant way. This is a bit tricky since some of the chess rules (e.g. King Castling, en passent, draws based on 3 or more repeated moves) are based not only on the board layout but also on the history of moves. I would prefer the format to be: textual human readable based on a standard (e.g. YAML, XML) easily parsable in a variety of languages But I am willing to sacrifice any of these for a suitable solution. My main question is: How can I build algorithms of such a complexity that operate on such complex state from a data format? A followup queston is: Can you provide an example of a similar problem solved in a similar manner that can act as a starting point? Edit: In response to a request for clarity -- consider that I will have a server written in Python, one client written in C# and another client written in Java. I would like to avoid specifying the rules (e.g. for allowable piece movement, circumstances for check, etc.) in each place. I would prefer to specify these rules once in a language independant manner.
Recommended data format for describing the rules of chess
0.088656
0
0
1,846
194,289
2008-10-11T16:34:00.000
2
0
0
0
c#,java,python,chess,dataformat
194,318
9
false
0
0
Edit: Overly wordy answer deleted. The short answer is, write the rules in Python. Use Iron Python to interface that to the C# client, and Jython for the Java client.
4
8
0
I'm going to be writing a chess server and one or more clients for chess and I want to describe the rules of chess (e.g. allowable moves based on game state, rules for when a game is complete) in a programming language independant way. This is a bit tricky since some of the chess rules (e.g. King Castling, en passent, draws based on 3 or more repeated moves) are based not only on the board layout but also on the history of moves. I would prefer the format to be: textual human readable based on a standard (e.g. YAML, XML) easily parsable in a variety of languages But I am willing to sacrifice any of these for a suitable solution. My main question is: How can I build algorithms of such a complexity that operate on such complex state from a data format? A followup queston is: Can you provide an example of a similar problem solved in a similar manner that can act as a starting point? Edit: In response to a request for clarity -- consider that I will have a server written in Python, one client written in C# and another client written in Java. I would like to avoid specifying the rules (e.g. for allowable piece movement, circumstances for check, etc.) in each place. I would prefer to specify these rules once in a language independant manner.
Recommended data format for describing the rules of chess
0.044415
0
0
1,846
194,289
2008-10-11T16:34:00.000
2
0
0
0
c#,java,python,chess,dataformat
194,332
9
false
0
0
I would suggest Prolog for describing the rules.
4
8
0
I'm going to be writing a chess server and one or more clients for chess and I want to describe the rules of chess (e.g. allowable moves based on game state, rules for when a game is complete) in a programming language independant way. This is a bit tricky since some of the chess rules (e.g. King Castling, en passent, draws based on 3 or more repeated moves) are based not only on the board layout but also on the history of moves. I would prefer the format to be: textual human readable based on a standard (e.g. YAML, XML) easily parsable in a variety of languages But I am willing to sacrifice any of these for a suitable solution. My main question is: How can I build algorithms of such a complexity that operate on such complex state from a data format? A followup queston is: Can you provide an example of a similar problem solved in a similar manner that can act as a starting point? Edit: In response to a request for clarity -- consider that I will have a server written in Python, one client written in C# and another client written in Java. I would like to avoid specifying the rules (e.g. for allowable piece movement, circumstances for check, etc.) in each place. I would prefer to specify these rules once in a language independant manner.
Recommended data format for describing the rules of chess
0.044415
0
0
1,846
194,289
2008-10-11T16:34:00.000
0
0
0
0
c#,java,python,chess,dataformat
297,803
9
false
0
0
I would agree with the comment left by ΤΖΩΤΖΙΟΥ, viz. just let the server do the validation and let the clients submit a potential move. If that's not the way you want to take the design, then just write the rules in Python as suggested by S. Lott and others. It really shouldn't be that hard. You can break the rules down into three major categories: - Rules that rely on the state of the board (castling, en passant, draws, check, checkmate, passing through check, is it even this player's turn, etc.) - Rules that apply to all pieces (can't occupy the same square as another piece of your own colour, moving to a square w/ opponent's piece == capture, can't move off the board) - Rules that apply to each individual piece. (pawns can't move backwards, castles can't move diagonally, etc) Each rule can be implemented as a function, and then for each half-move, validity is determined by seeing if it passes all of the validations. For each potential move submitted, you would just need to check the rules in the following order: is the proposed move potentially valid? (the right "shape" for the piece) does it fit the restraints of the board? (is the piece blocked, would it move off the edge) does the move violate state requirements? (am I in check after this move? do I move through check? is this en passant capture legal?) If all of those are ok, then the server should accept the move as legal…
4
8
0
I'm going to be writing a chess server and one or more clients for chess and I want to describe the rules of chess (e.g. allowable moves based on game state, rules for when a game is complete) in a programming language independant way. This is a bit tricky since some of the chess rules (e.g. King Castling, en passent, draws based on 3 or more repeated moves) are based not only on the board layout but also on the history of moves. I would prefer the format to be: textual human readable based on a standard (e.g. YAML, XML) easily parsable in a variety of languages But I am willing to sacrifice any of these for a suitable solution. My main question is: How can I build algorithms of such a complexity that operate on such complex state from a data format? A followup queston is: Can you provide an example of a similar problem solved in a similar manner that can act as a starting point? Edit: In response to a request for clarity -- consider that I will have a server written in Python, one client written in C# and another client written in Java. I would like to avoid specifying the rules (e.g. for allowable piece movement, circumstances for check, etc.) in each place. I would prefer to specify these rules once in a language independant manner.
Recommended data format for describing the rules of chess
0
0
0
1,846
195,101
2008-10-12T04:36:00.000
5
0
0
0
python,django,grails,groovy,web-applications
288,617
5
false
1
0
With Java hosting you don't need to do all the stupid tricks with apache, or nginx. Jetty itself can host everything you need, that's how the guys at www.mor.ph do it, and they find it to be pretty fast. The memory usage that way is pretty minimal, I host mine on a 256MB Ubuntu server from RapidXen, so it's about $10/month. I tried developing in Django, and while it runs all the scripts faster (like bootstrapping, or test cases) it's not as well-crafted in my oppinion
3
5
0
I'm currently in the planning stage for a web application and I find myself trying to decide on using Grails or Django. From an operation perspective: Which ecosystem is easier to maintain (migrations, backup, disaster recovery etc.)? If using grails it'll probably be a typical tomcat + mysql on linux. If django it'll be apache + mysql on linux. Does django or grails have a better choice of cheap and flexible hosting? Initially it'll probably be low bandwidth requirements. I'm not sure about the exact specs required, but from what I've been reading it seems like django would require far less server resources (even 256MB server is ok) than grails.
Running a web app in Grails vs Django
0.197375
0
0
5,101
195,101
2008-10-12T04:36:00.000
0
0
0
0
python,django,grails,groovy,web-applications
195,137
5
false
1
0
i think python tend to have lower hosting requirements (i.e., grails needs a jvm, and most el-cheapo hosts dont provide one, where as they usually provide python support). Plus google app engine supports django (to some extend). But if you got the dough, grails is so much better imho.
3
5
0
I'm currently in the planning stage for a web application and I find myself trying to decide on using Grails or Django. From an operation perspective: Which ecosystem is easier to maintain (migrations, backup, disaster recovery etc.)? If using grails it'll probably be a typical tomcat + mysql on linux. If django it'll be apache + mysql on linux. Does django or grails have a better choice of cheap and flexible hosting? Initially it'll probably be low bandwidth requirements. I'm not sure about the exact specs required, but from what I've been reading it seems like django would require far less server resources (even 256MB server is ok) than grails.
Running a web app in Grails vs Django
0
0
0
5,101
195,101
2008-10-12T04:36:00.000
2
0
0
0
python,django,grails,groovy,web-applications
197,592
5
false
1
0
I think from an operations perspective things are going to be close enough that you can base your decision on other criteria. If you can afford a virtual private server with at least 256 MB RAM you will be able to deploy Grails applications. If the cost seems like a lot check out Sun. They are really pushing hosting solutions based on their product stack and there are some greats deals available. I have free hosting from Layered Tech for a year through Ostatic.
3
5
0
I'm currently in the planning stage for a web application and I find myself trying to decide on using Grails or Django. From an operation perspective: Which ecosystem is easier to maintain (migrations, backup, disaster recovery etc.)? If using grails it'll probably be a typical tomcat + mysql on linux. If django it'll be apache + mysql on linux. Does django or grails have a better choice of cheap and flexible hosting? Initially it'll probably be low bandwidth requirements. I'm not sure about the exact specs required, but from what I've been reading it seems like django would require far less server resources (even 256MB server is ok) than grails.
Running a web app in Grails vs Django
0.07983
0
0
5,101
195,534
2008-10-12T14:14:00.000
14
1
0
0
python,apache,nginx,mod-wsgi
196,580
4
false
1
0
The main difference is that nginx is built to handle large numbers of connections in a much smaller memory space. This makes it very well suited for apps that are doing comet like connections that can have many idle open connections. This also gives it quite a smaller memory foot print. From a raw performance perspective, nginx is faster, but not so much faster that I would include that as a determining factor. Apache has the advantage in the area of modules available, and the fact that it is pretty much standard. Any web host you go with will have it installed, and most techs are going to be very familiar with it. Also, if you use mod_wsgi, it is your wsgi server so you don't even need cherrypy. Other than that, the best advice I can give is try setting up your app under both and do some benchmarking, since no matter what any one tells you, your mileage may vary.
1
68
0
What to use for a medium to large python WSGI application, Apache + mod_wsgi or Nginx + mod_wsgi? Which combination will need more memory and CPU time? Which one is faster? Which is known for being more stable than the other? I am also thinking to use CherryPy's WSGI server but I hear it's not very suitable for a very high-load application, what do you know about this? Note: I didn't use any Python Web Framework, I just wrote the whole thing from scratch. Note': Other suggestions are also welcome.
In production, Apache + mod_wsgi or Nginx + mod_wsgi?
1
0
0
31,610
195,625
2008-10-12T15:58:00.000
41
0
1
0
python
195,647
4
true
0
0
Pop() for the last element ought to be O(1) since you only need to return the element referred to by the last element in the array and update the index of the last element. I would expect pop() for an arbitrary element to be O(N) and require on average N/2 operations since you would need to move any elements beyond the element you are removing one position up in the array of pointers.
1
64
0
I wonder what is the time complexity of pop method of list objects in Python (in CPython particulary). Also does the value of N for list.pop(N) affects the complexity?
What is the time complexity of popping elements from list in Python?
1.2
0
0
64,836
196,217
2008-10-12T22:27:00.000
2
0
0
0
python,mysql,timeout
196,308
2
false
0
0
if the communication is such a problem, consider writing a 'proxy' that receives your SQL commands over the flaky connection and relays them to the MySQL server on a reliable channel (maybe running on the same box as the MySQL server). This way you have total control over failure detection and retrying.
2
2
0
Sometimes in our production environment occurs situation when connection between service (which is python program that uses MySQLdb) and mysql server is flacky, some packages are lost, some black magic happens and .execute() of MySQLdb.Cursor object never ends (or take great amount of time to end). This is very bad because it is waste of service worker threads. Sometimes it leads to exhausting of workers pool and service stops responding at all. So the question is: Is there a way to interrupt MySQLdb.Connection.execute operation after given amount of time?
MySQLdb execute timeout
0.197375
1
0
2,995
196,217
2008-10-12T22:27:00.000
1
0
0
0
python,mysql,timeout
196,891
2
false
0
0
You need to analyse exactly what the problem is. MySQL connections should eventually timeout if the server is gone; TCP keepalives are generally enabled. You may be able to tune the OS-level TCP timeouts. If the database is "flaky", then you definitely need to investigate how. It seems unlikely that the database really is the problem, more likely that networking in between is. If you are using (some) stateful firewalls of any kind, it's possible that they're losing some of the state, thus causing otherwise good long-lived connections to go dead. You might want to consider changing the idle timeout parameter in MySQL; otherwise, a long-lived, unused connection may go "stale", where the server and client both think it's still alive, but some stateful network element in between has "forgotten" about the TCP connection. An application trying to use such a "stale" connection will have a long wait before receiving an error (but it should eventually).
2
2
0
Sometimes in our production environment occurs situation when connection between service (which is python program that uses MySQLdb) and mysql server is flacky, some packages are lost, some black magic happens and .execute() of MySQLdb.Cursor object never ends (or take great amount of time to end). This is very bad because it is waste of service worker threads. Sometimes it leads to exhausting of workers pool and service stops responding at all. So the question is: Is there a way to interrupt MySQLdb.Connection.execute operation after given amount of time?
MySQLdb execute timeout
0.099668
1
0
2,995
196,755
2008-10-13T05:03:00.000
0
0
1
0
python,search,scripting,stackexchange-api
196,800
5
false
0
0
I would just use Pycurl to concatenate the search terms onto the query uri.
2
5
0
Given a string of keywords, such as "Python best practices", I would like to obtain the first 10 Stack Overflow questions that contain that keywords, sorted by relevance (?), say from a Python script. My goal is to end up with a list of tuples (title, URL). How can I accomplish this? Would you consider querying Google instead? (How would you do it from Python?)
How can I search through Stack Overflow questions from a script?
0
0
0
1,383
196,755
2008-10-13T05:03:00.000
1
0
1
0
python,search,scripting,stackexchange-api
196,758
5
false
0
0
You could screen scrape the returned HTML from a valid HTTP request. But that would result in bad karma, and the loss of the ability to enjoy a good night's sleep.
2
5
0
Given a string of keywords, such as "Python best practices", I would like to obtain the first 10 Stack Overflow questions that contain that keywords, sorted by relevance (?), say from a Python script. My goal is to end up with a list of tuples (title, URL). How can I accomplish this? Would you consider querying Google instead? (How would you do it from Python?)
How can I search through Stack Overflow questions from a script?
0.039979
0
0
1,383
196,924
2008-10-13T07:32:00.000
3
0
1
0
javascript,python,nlp
197,064
10
false
0
0
You are already doing NLP, if your module doesn't understand what language the text was then either the module doesn't work or the input was not in the correct language.
2
9
0
I am building a project involving natural language processing, since the nlp module currently only deal with english text, so I have to make sure the user submitted content (not long, only several words) is in english. Are there established ways to achieve this? Python or Javascript way preferred.
How to ensure user submit only english text
0.059928
0
0
1,046
196,924
2008-10-13T07:32:00.000
5
0
1
0
javascript,python,nlp
196,967
10
false
0
0
I think the most effective way would be to ask the users to submit english text only :) You can show a language selection drop-down over your text area with English/ Other as the options. When user selects "Other", disable the text area with a message that only English language is supported [at the moment].
2
9
0
I am building a project involving natural language processing, since the nlp module currently only deal with english text, so I have to make sure the user submitted content (not long, only several words) is in english. Are there established ways to achieve this? Python or Javascript way preferred.
How to ensure user submit only english text
0.099668
0
0
1,046
197,759
2008-10-13T14:26:00.000
1
1
1
0
python,string,unicode,encoding
197,854
5
false
0
0
I don't suppose you have any way of convincing the person who hosts the other machine to switch to unicode? This is one of the reasons Unicode was invented, after all.
2
9
0
I'm not exactly sure how to ask this question really, and I'm no where close to finding an answer, so I hope someone can help me. I'm writing a Python app that connects to a remote host and receives back byte data, which I unpack using Python's built-in struct module. My problem is with the strings, as they include multiple character encodings. Here is an example of such a string: "^LThis is an example ^Gstring with multiple ^Jcharacter encodings" Where the different encoding starts and ends is marked using special escape chars: ^L - Latin1 ^E - Central Europe ^T - Turkish ^B - Baltic ^J - Japanese ^C - Cyrillic ^G - Greek And so on... I need a way to convert this sort of string into Unicode, but I'm really not sure how to do it. I've read up on Python's codecs and string.encode/decode, but I'm none the wiser really. I should mention as well, that I have no control over how the strings are outputted by the host. I hope someone can help me with how to get started on this.
Dealing with a string containing multiple character encodings
0.039979
0
0
3,280
197,759
2008-10-13T14:26:00.000
3
1
1
0
python,string,unicode,encoding
197,786
5
false
0
0
I would write a codec that incrementally scanned the string and decoded the bytes as they came along. Essentially, you would have to separate strings into chunks with a consistent encoding and decode those and append them to the strings that followed them.
2
9
0
I'm not exactly sure how to ask this question really, and I'm no where close to finding an answer, so I hope someone can help me. I'm writing a Python app that connects to a remote host and receives back byte data, which I unpack using Python's built-in struct module. My problem is with the strings, as they include multiple character encodings. Here is an example of such a string: "^LThis is an example ^Gstring with multiple ^Jcharacter encodings" Where the different encoding starts and ends is marked using special escape chars: ^L - Latin1 ^E - Central Europe ^T - Turkish ^B - Baltic ^J - Japanese ^C - Cyrillic ^G - Greek And so on... I need a way to convert this sort of string into Unicode, but I'm really not sure how to do it. I've read up on Python's codecs and string.encode/decode, but I'm none the wiser really. I should mention as well, that I have no control over how the strings are outputted by the host. I hope someone can help me with how to get started on this.
Dealing with a string containing multiple character encodings
0.119427
0
0
3,280
198,692
2008-10-13T19:11:00.000
2
0
1
0
python,sqlite,pickle
198,763
14
false
0
0
Since Pickle can dump your object graph to a string it should be possible. Be aware though that TEXT fields in SQLite uses database encoding so you might need to convert it to a simple string before you un-pickle.
6
40
0
Any gotchas I should be aware of? Can I store it in a text field, or do I need to use a blob? (I'm not overly familiar with either pickle or sqlite, so I wanted to make sure I'm barking up the right tree with some of my high-level design ideas.)
Can I pickle a python dictionary into a sqlite3 text field?
0.028564
1
0
31,019
198,692
2008-10-13T19:11:00.000
5
0
1
0
python,sqlite,pickle
198,767
14
false
0
0
Pickle has both text and binary output formats. If you use the text-based format you can store it in a TEXT field, but it'll have to be a BLOB if you use the (more efficient) binary format.
6
40
0
Any gotchas I should be aware of? Can I store it in a text field, or do I need to use a blob? (I'm not overly familiar with either pickle or sqlite, so I wanted to make sure I'm barking up the right tree with some of my high-level design ideas.)
Can I pickle a python dictionary into a sqlite3 text field?
0.071307
1
0
31,019
198,692
2008-10-13T19:11:00.000
2
0
1
0
python,sqlite,pickle
198,770
14
false
0
0
If a dictionary can be pickled, it can be stored in text/blob field as well. Just be aware of the dictionaries that can't be pickled (aka that contain unpickable objects).
6
40
0
Any gotchas I should be aware of? Can I store it in a text field, or do I need to use a blob? (I'm not overly familiar with either pickle or sqlite, so I wanted to make sure I'm barking up the right tree with some of my high-level design ideas.)
Can I pickle a python dictionary into a sqlite3 text field?
0.028564
1
0
31,019
198,692
2008-10-13T19:11:00.000
2
0
1
0
python,sqlite,pickle
198,829
14
false
0
0
Yes, you can store a pickled object in a TEXT or BLOB field in an SQLite3 database, as others have explained. Just be aware that some object cannot be pickled. The built-in container types can (dict, set, list, tuple, etc.). But some objects, such as file handles, refer to state that is external to their own data structures, and other extension types have similar problems. Since a dictionary can contain arbitrary nested data structures, it might not be pickle-able.
6
40
0
Any gotchas I should be aware of? Can I store it in a text field, or do I need to use a blob? (I'm not overly familiar with either pickle or sqlite, so I wanted to make sure I'm barking up the right tree with some of my high-level design ideas.)
Can I pickle a python dictionary into a sqlite3 text field?
0.028564
1
0
31,019
198,692
2008-10-13T19:11:00.000
1
0
1
0
python,sqlite,pickle
199,190
14
false
0
0
SpoonMeiser is correct, you need to have a strong reason to pickle into a database. It's not difficult to write Python objects that implement persistence with SQLite. Then you can use the SQLite CLI to fiddle with the data as well. Which in my experience is worth the extra bit of work, since many debug and admin functions can be simply performed from the CLI rather than writing specific Python code. In the early stages of a project, I did what you propose and ended up re-writing with a Python class for each business object (note: I didn't say for each table!) This way the body of the application can focus on "what" needs to be done rather than "how" it is done.
6
40
0
Any gotchas I should be aware of? Can I store it in a text field, or do I need to use a blob? (I'm not overly familiar with either pickle or sqlite, so I wanted to make sure I'm barking up the right tree with some of my high-level design ideas.)
Can I pickle a python dictionary into a sqlite3 text field?
0.014285
1
0
31,019
198,692
2008-10-13T19:11:00.000
23
0
1
0
python,sqlite,pickle
198,748
14
true
0
0
If you want to store a pickled object, you'll need to use a blob, since it is binary data. However, you can, say, base64 encode the pickled object to get a string that can be stored in a text field. Generally, though, doing this sort of thing is indicative of bad design, since you're storing opaque data you lose the ability to use SQL to do any useful manipulation on that data. Although without knowing what you're actually doing, I can't really make a moral call on it.
6
40
0
Any gotchas I should be aware of? Can I store it in a text field, or do I need to use a blob? (I'm not overly familiar with either pickle or sqlite, so I wanted to make sure I'm barking up the right tree with some of my high-level design ideas.)
Can I pickle a python dictionary into a sqlite3 text field?
1.2
1
0
31,019
199,180
2008-10-13T22:08:00.000
3
1
0
0
python,vim,omnicomplete
213,253
6
false
0
0
Once I generated ctags for one of my site-packages, it started working for that package -- so I'm guessing that the omnicomplete function depends on ctags for non-sys modules. EDIT: Not true at all. Here's the problem -- poor testing on my part -- omnicomplete WAS working for parts of my project, just not most of it. The issue was that I'm working on a django project, and in order to import django.db, you need to have an environment variable set. Since I couldn't import django.db, any class that inherited from django.db, or any module that imported a class that inherited from django.db wouldn't complete.
1
9
0
The only thing I can get python omnicomplete to work with are system modules. I get nothing for help with modules in my site-packages or modules that I'm currently working on.
Is there any way to get python omnicomplete to work with non-system modules in vim?
0.099668
0
0
4,900
199,556
2008-10-14T00:23:00.000
1
0
0
0
java,php,python,django,jakarta-ee
219,328
4
false
1
0
A lot of the recommendations being given here are assuming you -- and just you -- are doing a full rewrite of the application. This is probably not the case, and it changes the answer quite a bit If you've already got J2EE kicking around, the correct answer is Grails. It simply is: you probably already have Hibernate and Spring kicking around, and you're going to want the ability to flip back and forth between your old code and your new with a minimum amount of pain. That's exactly Groovy's forte, and it is even smoother than JRuby in this regards. Also, if you've already got a J2EE app kicking around, you've already got Java developers kicking around. In that case, learning Groovy is like falling off a ladder -- literally. With the exception of anonymous inner classes, Groovy is a pure superset of Java, which means that you can write Java code, call it Groovy, and be done with it. As you become increasingly comfortable with the nicities of Groovy, you can integrate them into your Java-ish Groovy code. Before too long, you'll be writing very Groovy code, and not even really have realized the transition.
3
4
0
I want to move a legacy Java web application (J2EE) to a scripting language - any scripting language - in order to improve programming efficiency. What is the easiest way to do this? Are there any automated tools that can convert the bulk of the business logic?
How can I port a legacy Java/J2EE website to a modern scripting language (PHP,Python/Django, etc)?
0.049958
0
0
1,554
199,556
2008-10-14T00:23:00.000
6
0
0
0
java,php,python,django,jakarta-ee
199,593
4
false
1
0
Using an automated tool to "port" the web application will almost certainly guarantee that future programming efficiency will be minimised -- not improved. A good scripting language can help programming efficiency when used by good programmers who understand good coding practices in that language. Automated tools are usually not designed to output code that is elegent or well-written, only code that works. You'll only get an improvement in programming efficiency after you've put in the effort to re-implement the web app -- which, due to the time required for the reimplementation, may or may not result in an improvement overall.
3
4
0
I want to move a legacy Java web application (J2EE) to a scripting language - any scripting language - in order to improve programming efficiency. What is the easiest way to do this? Are there any automated tools that can convert the bulk of the business logic?
How can I port a legacy Java/J2EE website to a modern scripting language (PHP,Python/Django, etc)?
1
0
0
1,554
199,556
2008-10-14T00:23:00.000
11
0
0
0
java,php,python,django,jakarta-ee
199,736
4
false
1
0
Here's what you have to do. First, be sure you can walk before you run. Build something simple, possibly tangentially related to your main project. DO NOT build a piece of the final project and hope it will "evolve" into the final project. This never works out well. Why? You'll make dumb mistakes. But you can't delete or rework them because you're supposed to evolve that mistake into the final project. Next, pick a a framework. What? Second? Yes. Second. Until you actually do something with some scripting languages and frameworks, you have no real useful concept of what you're doing. Once you've built something, you now have an informed opinion. "Wait," you say. "To do step 1 I had to pick a framework." True. Step 1, however, contains decisions you're allowed to revoke. Pick the wrong framework for step 1 has no long-term bad effects. It was just learning. Third, with your strategic framework, and some experience, break down your existing site into pieces you can build with your new framework. Prioritize those pieces from most important to least important. DO NOT plan the entire conversion as one massive project. It never works. It makes a big job more complex than necessary. We'll use Django as the example framework. You'll have templates, view functions, model definitions, URL mapping and other details. For each build, do the following: Convert your existing model to a Django model. This won't ever fit your legacy SQL. You'll have to rethink your model, fix old mistakes, correct old bugs that you've always wanted to correct. Write unit tests. Build a conversion utility to export old data and import into the new model. Build Django admin pages to touch and feel the new data. Pick representative pages and rework them into the appropriate templates. You might make use of some legacy JSP pages. However, don't waste too much time with this. Use the HTML to create Django templates. Plan your URL's and view functions. Sometimes, these view functions will leverage legacy action classes. Don't "convert". Rewrite from scratch. Use your new language and framework. The only thing that's worth preserving is the data and the operational concept. Don't try to preserve or convert the code. It's misleading. You might convert unittests from JUnit to Python unittest. I gave this advice a few months ago. I had to do some coaching and review during the processing. The revised site is up and running. No conversion from the old technology; they did the suggested rewrite from scratch. Developer happy. Site works well.
3
4
0
I want to move a legacy Java web application (J2EE) to a scripting language - any scripting language - in order to improve programming efficiency. What is the easiest way to do this? Are there any automated tools that can convert the bulk of the business logic?
How can I port a legacy Java/J2EE website to a modern scripting language (PHP,Python/Django, etc)?
1
0
0
1,554
200,250
2008-10-14T07:27:00.000
1
0
0
0
python,apache,http,cookies
200,271
3
false
0
0
Return the header Set-Cookie: token=opaque; Domain=.your.domain; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/ The Domain and Path must match the original attributes that the cookie was issued under.
3
5
0
I've got a web system where users log in, and it stores a cookie of their session. When they log in as someone else or log out I want to remove that original cookie that I stored. What's the best way to do that? I'm using Python and Apache, though I suppose the answer will remain the same for most languages.
How do I remove a cookie that I've set on someone's computer?
0.066568
0
0
2,053
200,250
2008-10-14T07:27:00.000
4
0
0
0
python,apache,http,cookies
200,255
3
false
0
0
I guess the best way is to set the expiration to a date of the cookie to some date in the past.
3
5
0
I've got a web system where users log in, and it stores a cookie of their session. When they log in as someone else or log out I want to remove that original cookie that I stored. What's the best way to do that? I'm using Python and Apache, though I suppose the answer will remain the same for most languages.
How do I remove a cookie that I've set on someone's computer?
0.26052
0
0
2,053
200,250
2008-10-14T07:27:00.000
7
0
0
0
python,apache,http,cookies
200,265
3
true
0
0
Set the cookie again, as if you hadn't set it the first time, but specify an expiration date that is in the past.
3
5
0
I've got a web system where users log in, and it stores a cookie of their session. When they log in as someone else or log out I want to remove that original cookie that I stored. What's the best way to do that? I'm using Python and Apache, though I suppose the answer will remain the same for most languages.
How do I remove a cookie that I've set on someone's computer?
1.2
0
0
2,053
200,599
2008-10-14T10:04:00.000
0
0
1
0
python,database,web,settings
201,272
12
false
0
0
I agree with the reply about using Pickled Dictionary. Very simple and effective for storing simple data in a Dictionary structure.
3
8
0
I am programming a website in which users will have a number of settings, such as their choice of colour scheme, etc. I'm happy to store these as plain text files, and security is not an issue. The way I currently see it is: there is a dictionary, where all the keys are users and the values are dictionaries with the users' settings in them. For example, userdb["bob"]["colour_scheme"] would have the value "blue". What is the best way to store it on file? Pickling the dictionary? Are there better ways of doing what I am trying to do?
Store simple user settings in Python
0
0
0
10,429
200,599
2008-10-14T10:04:00.000
0
0
1
0
python,database,web,settings
201,020
12
false
0
0
Is there are particular reason you're not using the database for this? it seems the normal and natural thing to do - or store a pickle of the settings in the db keyed on user id or something. You haven't described the usage patterns of the website, but just thinking of a general website - but I would think that keeping the settings in a database would cause much less disk I/O than using files. OTOH, for settings that might be used by client-side code, storing them as javascript in a static file that can be cached would be handy - at the expense of having multiple places you might have settings. (I'd probably store those settings in the db, and rebuild the static files as necessary)
3
8
0
I am programming a website in which users will have a number of settings, such as their choice of colour scheme, etc. I'm happy to store these as plain text files, and security is not an issue. The way I currently see it is: there is a dictionary, where all the keys are users and the values are dictionaries with the users' settings in them. For example, userdb["bob"]["colour_scheme"] would have the value "blue". What is the best way to store it on file? Pickling the dictionary? Are there better ways of doing what I am trying to do?
Store simple user settings in Python
0
0
0
10,429
200,599
2008-10-14T10:04:00.000
0
0
1
0
python,database,web,settings
200,621
12
false
0
0
If you have a database, I might suggest storing the settings in the database. However, it sounds like ordinary files might suit your environment better. You probably don't want to store all the users settings in the same file, because you might run into trouble with concurrent access to that one file. If you stored each user's settings as a dictionary in their own pickled file, then they would be able to act independently. Pickling is a reasonable way to store such data, but unfortunately the pickle data format is notoriously not-human-readable. You might be better off storing it as repr(dictionary) which will be a more readable format. To reload the user settings, use eval(open("file").read()) or something like that.
3
8
0
I am programming a website in which users will have a number of settings, such as their choice of colour scheme, etc. I'm happy to store these as plain text files, and security is not an issue. The way I currently see it is: there is a dictionary, where all the keys are users and the values are dictionaries with the users' settings in them. For example, userdb["bob"]["colour_scheme"] would have the value "blue". What is the best way to store it on file? Pickling the dictionary? Are there better ways of doing what I am trying to do?
Store simple user settings in Python
0
0
0
10,429
203,758
2008-10-15T04:55:00.000
1
0
1
0
python,sockets
203,769
3
false
0
0
What is your question exactly? What happens when you do receive on a socket is that the current available data in the socket buffer is immediately returned. If you give receive (or read, I guess), a huge buffer size, such as 40000, it'll likely never return that much data at once. If you give it a tiny buffer size like 100, then it'll return the 100 bytes it has immediately and still have more available. Either way, you're not imposing a limit on how much data the client is sending you.
3
2
0
I am writing a program in Python that will act as a server and accept data from a client, is it a good idea to impose a hard limit as to the amount of data, if so why? More info: So certain chat programs limit the amount of text one can send per send (i.e. per time user presses send) so the question comes down to is there a legit reason for this and if yes, what is it?
Receive socket size limits good?
0.066568
0
1
1,350
203,758
2008-10-15T04:55:00.000
2
0
1
0
python,sockets
203,933
3
true
0
0
Most likely you've seen code which protects against "extra" incoming data. This is often due to the possibility of buffer overruns, where the extra data being copied into memory overruns the pre-allocated array and overwrites executable code with attacker code. Code written in languages like C typically has a lot of length checking to prevent this type of attack. Functions such as gets, and strcpy are replaced with their safer counterparts like fgets and strncpy which have a length argument to prevent buffer overruns. If you use a dynamic language like Python, your arrays resize so they won't overflow and clobber other memory, but you still have to be careful about sanitizing foreign data. Chat programs likely limit the size of a message for reasons such as database field size. If 80% of your incoming messages are 40 characters or less, 90% are 60 characters or less, and 98% are 80 characters or less, why make your message text field allow 10k characters per message?
3
2
0
I am writing a program in Python that will act as a server and accept data from a client, is it a good idea to impose a hard limit as to the amount of data, if so why? More info: So certain chat programs limit the amount of text one can send per send (i.e. per time user presses send) so the question comes down to is there a legit reason for this and if yes, what is it?
Receive socket size limits good?
1.2
0
1
1,350
203,758
2008-10-15T04:55:00.000
0
0
1
0
python,sockets
207,096
3
false
0
0
I don't know what your actual application is, however, setting a hard limit on the total amount of data that a client can send could be useful in reducing your exposure to denial of service attacks, e.g. client connects and sends 100MB of data which could load your application unacceptably. But it really depends on what you application is. Are you after a per line limit or a total per connection limit or what?
3
2
0
I am writing a program in Python that will act as a server and accept data from a client, is it a good idea to impose a hard limit as to the amount of data, if so why? More info: So certain chat programs limit the amount of text one can send per send (i.e. per time user presses send) so the question comes down to is there a legit reason for this and if yes, what is it?
Receive socket size limits good?
0
0
1
1,350
203,912
2008-10-15T06:59:00.000
1
0
1
0
python,multicore
203,923
7
false
0
0
The main difference is how you organize and distribute data. Multicore typically has higher bandwidths between the different cores in a cpu, and multiprocessor needs to involve the bus between the cpus more. Python 2.6 has gotten multiprocess (process, as in program running) and more synchronization and communication objects for multithreaded programming.
1
70
0
What is the difference between multiprocessor programming and multicore programming? preferably show examples in python how to write a small program for multiprogramming & multicore programming
Does python support multiprocessor/multicore programming?
0.028564
0
0
71,173
204,062
2008-10-15T08:42:00.000
5
0
1
0
python,winapi,service,alerts
204,082
1
true
0
0
No, Windows services run on a completely separate hidden desktop and have no access to the logged-on user's desktop. There is no way around this from a service developer's perspective. In previous versions of Windows, it was possible for a service to be marked as "allowed to interact with the user desktop", but this option was removed in XP or Vista (I forget which). Now, services cannot interact with the user desktop. One solution to your problem might be to have a desktop application that communicates with the service through some IPC method. When the service wants to alert the user of some condition, it would notify the desktop application which would then display a regular message box.
1
3
0
I have been using win32api.MessageBox to do alerts, and this works for apps running from the interactive prompt and normally executed code, however when I built a Python service when a MessageBox is triggered I can hear the 'beep' but the box does not display. Is it possible to display alerts from services?
Alert Popups from service in Python
1.2
0
0
958
204,802
2008-10-15T13:57:00.000
2
0
0
0
php,python,lighttpd,cherrypy,high-load
244,836
5
false
1
0
I would go with nginx + php + xcache + postgresql
4
7
0
For a website like reddit with lots of up/down votes and lots of comments per topic what should I go with? Lighttpd/Php or Lighttpd/CherryPy/Genshi/SQLAlchemy? and for database what would scale better / be fastest MySQL ( 4.1 or 5 ? ) or PostgreSQL?
What would you recommend for a high traffic ajax intensive website?
0.07983
1
0
1,670
204,802
2008-10-15T13:57:00.000
2
0
0
0
php,python,lighttpd,cherrypy,high-load
204,854
5
false
1
0
Going to need more data. Jeff had a few articles on the same problems and the answer was to wait till you hit a performance issue. to start with - who is hosting and what do they have available ? what's your in house talent skill sets ? Are you going to be hiring an outside firm ? what do they recommend ? brand new project w/ a team willing to learn a new framework ? 2nd thing is to do some mockups - how is the interface going to work. what data does it need to load and persist ? the idea is to keep your traffic between the web and db side down. e.g. no chatty pages with lots of queries. etc. Once you have a better idea of the data requirements and flow - then work on the database design. there are plenty of rules to follow but one of the better ones is to follow normalization rules (yea i'm a db guy why ?) Now you have a couple of pages build - run your tests. are you having a problem ? Yes, now look at what is it. Page serving or db pulls ? Measure then pick a course of action.
4
7
0
For a website like reddit with lots of up/down votes and lots of comments per topic what should I go with? Lighttpd/Php or Lighttpd/CherryPy/Genshi/SQLAlchemy? and for database what would scale better / be fastest MySQL ( 4.1 or 5 ? ) or PostgreSQL?
What would you recommend for a high traffic ajax intensive website?
0.07983
1
0
1,670
204,802
2008-10-15T13:57:00.000
8
0
0
0
php,python,lighttpd,cherrypy,high-load
204,853
5
true
1
0
I can't speak to the MySQL/PostgreSQL question as I have limited experience with Postgres, but my Masters research project was about high-performance websites with CherryPy, and I don't think you'll be disappointed if you use CherryPy for your site. It can easily scale to thousands of simultaneous users on commodity hardware. Of course, the same could be said for PHP, and I don't know of any reasonable benchmarks comparing PHP and CherryPy performance. But if you were wondering whether CherryPy can handle a high-traffic site with a huge number of requests per second, the answer is definitely yes.
4
7
0
For a website like reddit with lots of up/down votes and lots of comments per topic what should I go with? Lighttpd/Php or Lighttpd/CherryPy/Genshi/SQLAlchemy? and for database what would scale better / be fastest MySQL ( 4.1 or 5 ? ) or PostgreSQL?
What would you recommend for a high traffic ajax intensive website?
1.2
1
0
1,670
204,802
2008-10-15T13:57:00.000
3
0
0
0
php,python,lighttpd,cherrypy,high-load
205,425
5
false
1
0
On the DB question, I'd say PostgreSQL scales better and has better data integrity than MySQL. For a small site MySQL might be faster, but from what I've heard it slows significantly as the size of the database grows. (Note: I've never used MySQL for a large database, so you should probably get a second opinion about its scalability.) But PostgreSQL definitely scales well, and would be a good choice for a high traffic site.
4
7
0
For a website like reddit with lots of up/down votes and lots of comments per topic what should I go with? Lighttpd/Php or Lighttpd/CherryPy/Genshi/SQLAlchemy? and for database what would scale better / be fastest MySQL ( 4.1 or 5 ? ) or PostgreSQL?
What would you recommend for a high traffic ajax intensive website?
0.119427
1
0
1,670
205,062
2008-10-15T15:02:00.000
1
1
1
0
python,module,compilation
209,176
4
false
0
0
I think you can use jython to compile python to Java bytecode, and then compile that with GCJ.
1
14
0
I wonder if it is possible to create an executable module from a Python script. I need to have the most performance and the flexibility of Python script, without needing to run in the Python environment. I would use this code to load on demand user modules to customize my application.
Is it possible to compile Python natively (beyond pyc byte code)?
0.049958
0
0
4,549
205,204
2008-10-15T15:37:00.000
1
0
0
0
javascript,python,frameworks
213,325
5
false
1
0
web2py uses jQuery
1
1
0
I am starting a new web application project. I want to use python as I am using it at my bread-and-butter-job. However I don't want to reinvent the wheel. Some things I have thought about: AJAX would be nice if it’s not too much of a hazzle. It is best if the licensing allows commercialization but is not crucial at this point. It could also be funny to try out the Google App Engine if the tools will let me. Should I be using a javascript UI framework or should I go for standard HTML forms? Which framework would you recommend?
Starting a new database driven python web application would you use a javascript widget framework? If so which framework?
0.039979
0
0
2,019
205,704
2008-10-15T17:46:00.000
2
1
0
0
python,validation,emacs,syntax
207,059
5
false
0
0
Or from emacs (or vim) you could run python -c 'import x' where x is the name of your file minus the .py extension.
2
15
0
Python's IDLE has 'Check Module' (Alt-X) to check the syntax which can be called without needing to run the code. Is there an equivalent way to do this in Emacs instead of running and executing the code?
How can I check the syntax of Python code in Emacs without actually executing it?
0.07983
0
0
8,119
205,704
2008-10-15T17:46:00.000
0
1
0
0
python,validation,emacs,syntax
207,593
5
false
0
0
You can use pylint, pychecker, pyflakes etc. from Emacs' compile command (M-x compile). Hint: bind a key (say, F5) to recompile.
2
15
0
Python's IDLE has 'Check Module' (Alt-X) to check the syntax which can be called without needing to run the code. Is there an equivalent way to do this in Emacs instead of running and executing the code?
How can I check the syntax of Python code in Emacs without actually executing it?
0
0
0
8,119
206,823
2008-10-15T22:49:00.000
1
1
0
1
python,ruby,interop
4,859,776
5
false
0
0
Expose your Ruby classes as web services using Sinatra, Rails, or, plain old Rack. Expose your Python classes as web services using web.py, flask, Django, or App Engine. Use HTTParty for Ruby to build an API into your Python classes. Use a Python REST library to build an API into your Ruby classes.
2
8
0
I am interested in getting some Python code talking to some Ruby code on Windows, Linux and possibly other platforms. Specificlly I would like to access classes in Ruby from Python and call their methods, access their data, create new instances and so on. An obvious way to do this is via something like XML-RPC or maybe CORBA but I would be interested in any other approaches. What have other people done to get code from Python and Ruby communicating with one another, either locally on the same system or remotely accross a network? Thanks in advance.
Ruby to Python bridge
0.039979
0
0
2,499
206,823
2008-10-15T22:49:00.000
3
1
0
1
python,ruby,interop
206,839
5
false
0
0
Please be advised that I don't speak from personal experience here, but I imagine JRuby and Jython (The ruby and python implementations in the JVM) would be able to to easily talk to each other, as well as Java code. You may want to look into that.
2
8
0
I am interested in getting some Python code talking to some Ruby code on Windows, Linux and possibly other platforms. Specificlly I would like to access classes in Ruby from Python and call their methods, access their data, create new instances and so on. An obvious way to do this is via something like XML-RPC or maybe CORBA but I would be interested in any other approaches. What have other people done to get code from Python and Ruby communicating with one another, either locally on the same system or remotely accross a network? Thanks in advance.
Ruby to Python bridge
0.119427
0
0
2,499
207,234
2008-10-16T02:32:00.000
24
0
0
1
python,networking
207,246
11
true
0
0
If by "local" you mean on the same network segment, then you have to perform the following steps: Determine your own IP address Determine your own netmask Determine the network range Scan all the addresses (except the lowest, which is your network address and the highest, which is your broadcast address). Use your DNS's reverse lookup to determine the hostname for IP addresses which respond to your scan. Or you can just let Python execute nmap externally and pipe the results back into your program.
1
46
0
How can I get a list of the IP addresses or host names from a local network easily in Python? It would be best if it was multi-platform, but it needs to work on Mac OS X first, then others follow. Edit: By local I mean all active addresses within a local network, such as 192.168.xxx.xxx. So, if the IP address of my computer (within the local network) is 192.168.1.1, and I have three other connected computers, I would want it to return the IP addresses 192.168.1.2, 192.168.1.3, 192.168.1.4, and possibly their hostnames.
List of IP addresses/hostnames from local network in Python
1.2
0
1
129,230
207,290
2008-10-16T03:02:00.000
1
0
1
0
python,parsing
209,420
4
false
0
0
If you want to handle arbitrary expressions like {'{spam': 42}["spam}"], you can't get away without full-blown parser.
1
1
0
I've been wondering about how hard it would be to write some Python code to search a string for the index of a substring of the form ${expr}, for example, where expr is meant to be a Python expression or something resembling one. Given such a thing, one could easily imagine going on to check the expression's syntax with compile(), evaluate it against a particular scope with eval(), and perhaps even substitute the result into the original string. People must do very similar things all the time. I could imagine solving such a problem using a third-party parser generator [oof], or by hand-coding some sort of state machine [eek], or perhaps by convincing Python's own parser to do the heavy lifting somehow [hmm]. Maybe there's a third-party templating library somewhere that can be made to do exactly this. Maybe restricting the syntax of expr is likely to be a worthwhile compromise in terms of simplicity or execution time or cutting down on external dependencies -- for example, maybe all I really need is something that matches any expr that has balanced curly braces. What's your sense? Update: Thanks very much for your responses so far! Looking back at what I wrote yesterday, I'm not sure I was sufficiently clear about what I'm asking. Template substitution is indeed an interesting problem, and probably much more useful to many more people than the expression extraction subproblem I'm wondering about, but I brought it up only as a simple example of how the answer to my question might be useful in real life. Some other potential applications might include passing the extracted expressions to a syntax highlighter; passing the result to a real Python parser and looking at or monkeying with the parse tree; or using the sequence of extracted expressions to build up a larger Python program, perhaps in conjunction with some information taken from the surrounding text. The ${expr} syntax I mentioned is also intended as an example, and in fact I wonder if I shouldn't have used $(expr) as my example instead, because it makes the potential drawbacks of the obvious approach, along the lines of re.finditer(r'$\{([^}]+)\}', s), a bit easier to see. Python expressions can (and often do) contain the ) (or }) character. It seems possible that handling any of those cases might be much more trouble than it's worth, but I'm not convinced of that yet. Please feel free to try to make this case! Prior to posting this question, I spent quite a bit of time looking at Python template engines hoping that one might expose the sort of low-level functionality I'm asking about -- namely, something that can find expressions in a variety of contexts and tell me where they are rather than being limited to finding expressions embedded using a single hard-coded syntax, always evaluating them, and always substituting the results back into the original string. I haven't figured out how to use any of them to solve my problem yet, but I do very much appreciate the suggestions regarding more to look at (can't believe I missed that wonderful list on the wiki!). The API documentation for these things tends to be pretty high-level, and I'm not too familiar with the internals of any of them, so I'm sure I could use help looking at those and figuring out how to get them to do this sort of thing. Thanks for your patience!
Extracting a parenthesized Python expression from a string
0.049958
0
0
1,094
207,904
2008-10-16T09:21:00.000
2
0
1
0
python,debugging,pdb,watchpoint
207,968
5
true
0
0
Please look what pydev in eclipse offers...
1
8
0
pdb and winpdb both seem to be missing this essential (to me) feature. I saw something suggesting WingIDE has it but I'd prefer a solution that is free, and if I do have to pay, I'd prefer to pay for something that is better than Wing.
Is there a free python debugger that has watchpoints?
1.2
0
0
3,022
209,470
2008-10-16T17:11:00.000
6
1
1
0
python,bash,shell
20,313,297
17
false
0
0
I will give here my opinion based on experience: For shell: shell can very easily spawn read-only code. Write it and when you come back to it, you will never figure out what you did again. It's very easy to accomplish this. shell can do A LOT of text processing, splitting, etc in one line with pipes. it is the best glue language when it comes to integrate the call of programs in different programming languages. For python: if you want portability to windows included, use python. python can be better when you must manipulate just more than text, such as collections of numbers. For this, I recommend python. I usually choose bash for most of the things, but when I have something that must cross windows boundaries, I just use python.
5
242
0
I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl. I've seen mentioned a few places that python is good for this kind of thing. How can I use Python to replace shell scripting, AWK, sed and friends?
How to implement common bash idioms in Python?
1
0
0
115,137
209,470
2008-10-16T17:11:00.000
2
1
1
0
python,bash,shell
209,665
17
false
0
0
Your best bet is a tool that is specifically geared towards your problem. If it's processing text files, then Sed, Awk and Perl are the top contenders. Python is a general-purpose dynamic language. As with any general purpose language, there's support for file-manipulation, but that isn't what it's core purpose is. I would consider Python or Ruby if I had a requirement for a dynamic language in particular. In short, learn Sed and Awk really well, plus all the other goodies that come with your flavour of *nix (All the Bash built-ins, grep, tr and so forth). If it's text file processing you're interested in, you're already using the right stuff.
5
242
0
I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl. I've seen mentioned a few places that python is good for this kind of thing. How can I use Python to replace shell scripting, AWK, sed and friends?
How to implement common bash idioms in Python?
0.023525
0
0
115,137
209,470
2008-10-16T17:11:00.000
3
1
1
0
python,bash,shell
210,429
17
false
0
0
I have built semi-long shell scripts (300-500 lines) and Python code which does similar functionality. When many external commands are being executed, I find the shell is easier to use. Perl is also a good option when there is lots of text manipulation.
5
242
0
I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl. I've seen mentioned a few places that python is good for this kind of thing. How can I use Python to replace shell scripting, AWK, sed and friends?
How to implement common bash idioms in Python?
0.035279
0
0
115,137
209,470
2008-10-16T17:11:00.000
16
1
1
0
python,bash,shell
210,290
17
false
0
0
In the beginning there was sh, sed, and awk (and find, and grep, and...). It was good. But awk can be an odd little beast and hard to remember if you don't use it often. Then the great camel created Perl. Perl was a system administrator's dream. It was like shell scripting on steroids. Text processing, including regular expressions were just part of the language. Then it got ugly... People tried to make big applications with Perl. Now, don't get me wrong, Perl can be an application, but it can (can!) look like a mess if you're not really careful. Then there is all this flat data business. It's enough to drive a programmer nuts. Enter Python, Ruby, et al. These are really very good general purpose languages. They support text processing, and do it well (though perhaps not as tightly entwined in the basic core of the language). But they also scale up very well, and still have nice looking code at the end of the day. They also have developed pretty hefty communities with plenty of libraries for most anything. Now, much of the negativeness towards Perl is a matter of opinion, and certainly some people can write very clean Perl, but with this many people complaining about it being too easy to create obfuscated code, you know some grain of truth is there. The question really becomes then, are you ever going to use this language for more than simple bash script replacements. If not, learn some more Perl.. it is absolutely fantastic for that. If, on the other hand, you want a language that will grow with you as you want to do more, may I suggest Python or Ruby. Either way, good luck!
5
242
0
I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl. I've seen mentioned a few places that python is good for this kind of thing. How can I use Python to replace shell scripting, AWK, sed and friends?
How to implement common bash idioms in Python?
1
0
0
115,137
209,470
2008-10-16T17:11:00.000
7
1
1
0
python,bash,shell
16,726,383
17
false
0
0
One reason I love Python is that it is much better standardized than the POSIX tools. I have to double and triple check that each bit is compatible with other operating systems. A program written on a Linux system might not work the same on a BSD system of OSX. With Python, I just have to check that the target system has a sufficiently modern version of Python. Even better, a program written in standard Python will even run on Windows!
5
242
0
I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl. I've seen mentioned a few places that python is good for this kind of thing. How can I use Python to replace shell scripting, AWK, sed and friends?
How to implement common bash idioms in Python?
1
0
0
115,137
209,888
2008-10-16T19:19:00.000
2
0
1
0
python,python-3.x,python-2.x
209,907
6
false
0
0
Python 2.x has been out long enough to build up quite a few tutorials already, but 3k has much less resources available. Some intro level 3k stuff would probably see more general purpose use. So unless you're tailoring this to a specific sub domain that lacks any python resources, 3k would be of greater use.
4
7
0
Python 3.0 is in beta with a final release coming shortly. Obviously it will take some significant time for general adoption and for it to eventually replace 2.x. I am writing a tutorial about certain aspects of programming Python. I'm wondering if I should do it in Python 2.x or 3.0? (not that the difference is huge) a 2.x tutorial is probably more useful now, but it would be nice to start producing 3.0 tutorials. anyone have thoughts? (of course I could do both, but I would prefer to do one or the other)
Tutorial for Python - Should I use 2.x or 3.0?
0.066568
0
0
3,359
209,888
2008-10-16T19:19:00.000
2
0
1
0
python,python-3.x,python-2.x
209,911
6
false
0
0
Learn Python 3.0, as contagious suggests. Python 2.x is not very different, there seems to be a great deal of FUD about the rather minor differences between them. Sure, the differences are great enough that most programs will need to be modified, but almost all of the modifications are straightforward (like changing print statement to print function). In fact, Python 2.6 can optionally enable all the new syntactic features of Python 3.0. It's a very well-thought-out transition process.
4
7
0
Python 3.0 is in beta with a final release coming shortly. Obviously it will take some significant time for general adoption and for it to eventually replace 2.x. I am writing a tutorial about certain aspects of programming Python. I'm wondering if I should do it in Python 2.x or 3.0? (not that the difference is huge) a 2.x tutorial is probably more useful now, but it would be nice to start producing 3.0 tutorials. anyone have thoughts? (of course I could do both, but I would prefer to do one or the other)
Tutorial for Python - Should I use 2.x or 3.0?
0.066568
0
0
3,359
209,888
2008-10-16T19:19:00.000
0
0
1
0
python,python-3.x,python-2.x
209,910
6
false
0
0
The differences are small enough that it's really not going to matter much.
4
7
0
Python 3.0 is in beta with a final release coming shortly. Obviously it will take some significant time for general adoption and for it to eventually replace 2.x. I am writing a tutorial about certain aspects of programming Python. I'm wondering if I should do it in Python 2.x or 3.0? (not that the difference is huge) a 2.x tutorial is probably more useful now, but it would be nice to start producing 3.0 tutorials. anyone have thoughts? (of course I could do both, but I would prefer to do one or the other)
Tutorial for Python - Should I use 2.x or 3.0?
0
0
0
3,359
209,888
2008-10-16T19:19:00.000
0
0
1
0
python,python-3.x,python-2.x
209,893
6
false
0
0
It depends on your audience. If it's a general audience, and you plan to leave it posted for a long time, I'd suggest looking forward and going with 3.0. On the other hand if it's for a project or group that's going to be doing work in the near future, Python 2 probably make more sense.
4
7
0
Python 3.0 is in beta with a final release coming shortly. Obviously it will take some significant time for general adoption and for it to eventually replace 2.x. I am writing a tutorial about certain aspects of programming Python. I'm wondering if I should do it in Python 2.x or 3.0? (not that the difference is huge) a 2.x tutorial is probably more useful now, but it would be nice to start producing 3.0 tutorials. anyone have thoughts? (of course I could do both, but I would prefer to do one or the other)
Tutorial for Python - Should I use 2.x or 3.0?
0
0
0
3,359
210,978
2008-10-17T03:04:00.000
0
0
0
1
python,shell,exec
211,898
2
false
1
0
Make sure you aren't relying on shell expansion in your classpath. E.g. "~/my.jar" will get expanded by the shell in an os.system call, but not, I believe in an os.execvp call.
1
7
0
I have a question about using os.execvp in Python. I have the following bit of code that's used to create a list of arguments: args = [ "java" , classpath , "-Djava.library.path=" + lib_path() , ea , "-Xmx1000m" , "-server" , "code_swarm" , params ] When I output a string using " ".join(args) and paste that into my shell prompt, the JVM launches fine, and everything works. Everything works if I use os.system(" ".join(args)) in my Python script, too. But the following bit of code does not work: os.execvp("java", args) I get the following error: Unrecognized option: -classpath [and then the classpath I created, which looks okay] Could not create the Java virtual machine. So what gives? Why does copying/pasting into the shell or using os.system() work, but not os.execvp()?
Using os.execvp in Python
0
0
0
11,349
211,160
2008-10-17T05:30:00.000
1
1
0
0
python,algorithm,matrix,linear-algebra,matrix-inverse
213,717
7
false
0
0
If you hate numpy, get out RPy and your local copy of R, and use it instead. (I would also echo to make you you really need to invert the matrix. In R, for example, linalg.solve and the solve() function don't actually do a full inversion, since it is unnecessary.)
1
62
1
How do I get the inverse of a matrix in python? I've implemented it myself, but it's pure python, and I suspect there are faster modules out there to do it.
Python Inverse of a Matrix
0.028564
0
0
125,109
211,501
2008-10-17T09:02:00.000
0
0
0
0
python,exception,sqlite
214,623
8
false
0
0
Yes, I was nuking out the problem. All I needed to do was check for the file and catch the IOError if it didn't exist. Thanks for all the other answers. They may come in handy in the future.
5
13
0
I have created a Python module that creates and populates several SQLite tables. Now, I want to use it in a program but I don't really know how to call it properly. All the tutorials I've found are essentially "inline", i.e. they walk through using SQLite in a linear fashion rather than how to actually use it in production. What I'm trying to do is have a method check to see if the database is already created. If so, then I can use it. If not, an exception is raised and the program will create the database. (Or use if/else statements, whichever is better). I created a test script to see if my logic is correct but it's not working. When I create the try statement, it just creates a new database rather than checking if one already exists. The next time I run the script, I get an error that the table already exists, even if I tried catching the exception. (I haven't used try/except before but figured this is a good time to learn). Are there any good tutorials for using SQLite operationally or any suggestions on how to code this? I've looked through the pysqlite tutorial and others I found but they don't address this.
Using SQLite in a Python program
0
1
0
31,269
211,501
2008-10-17T09:02:00.000
3
0
0
0
python,exception,sqlite
211,539
8
false
0
0
Doing SQL in overall is horrible in any language I've picked up. SQLalchemy has shown to be easiest from them to use because actual query and committing with it is so clean and absent from troubles. Here's some basic steps on actually using sqlalchemy in your app, better details can be found from the documentation. provide table definitions and create ORM-mappings load database ask it to create tables from the definitions (won't do so if they exist) create session maker (optional) create session After creating a session, you can commit and query from the database.
5
13
0
I have created a Python module that creates and populates several SQLite tables. Now, I want to use it in a program but I don't really know how to call it properly. All the tutorials I've found are essentially "inline", i.e. they walk through using SQLite in a linear fashion rather than how to actually use it in production. What I'm trying to do is have a method check to see if the database is already created. If so, then I can use it. If not, an exception is raised and the program will create the database. (Or use if/else statements, whichever is better). I created a test script to see if my logic is correct but it's not working. When I create the try statement, it just creates a new database rather than checking if one already exists. The next time I run the script, I get an error that the table already exists, even if I tried catching the exception. (I haven't used try/except before but figured this is a good time to learn). Are there any good tutorials for using SQLite operationally or any suggestions on how to code this? I've looked through the pysqlite tutorial and others I found but they don't address this.
Using SQLite in a Python program
0.07486
1
0
31,269
211,501
2008-10-17T09:02:00.000
7
0
0
0
python,exception,sqlite
211,573
8
false
0
0
SQLite automatically creates the database file the first time you try to use it. The SQL statements for creating tables can use IF NOT EXISTS to make the commands only take effect if the table has not been created This way you don't need to check for the database's existence beforehand: SQLite can take care of that for you. The main thing I would still be worried about is that executing CREATE TABLE IF EXISTS for every web transaction (say) would be inefficient; you can avoid that by having the program keep an (in-memory) variable saying whether it has created the database today, so it runs the CREATE TABLE script once per run. This would still allow for you to delete the database and start over during debugging.
5
13
0
I have created a Python module that creates and populates several SQLite tables. Now, I want to use it in a program but I don't really know how to call it properly. All the tutorials I've found are essentially "inline", i.e. they walk through using SQLite in a linear fashion rather than how to actually use it in production. What I'm trying to do is have a method check to see if the database is already created. If so, then I can use it. If not, an exception is raised and the program will create the database. (Or use if/else statements, whichever is better). I created a test script to see if my logic is correct but it's not working. When I create the try statement, it just creates a new database rather than checking if one already exists. The next time I run the script, I get an error that the table already exists, even if I tried catching the exception. (I haven't used try/except before but figured this is a good time to learn). Are there any good tutorials for using SQLite operationally or any suggestions on how to code this? I've looked through the pysqlite tutorial and others I found but they don't address this.
Using SQLite in a Python program
1
1
0
31,269
211,501
2008-10-17T09:02:00.000
29
0
0
0
python,exception,sqlite
211,660
8
false
0
0
Don't make this more complex than it needs to be. The big, independent databases have complex setup and configuration requirements. SQLite is just a file you access with SQL, it's much simpler. Do the following. Add a table to your database for "Components" or "Versions" or "Configuration" or "Release" or something administrative like that. CREATE TABLE REVISION( RELEASE_NUMBER CHAR(20) ); In your application, connect to your database normally. Execute a simple query against the revision table. Here's what can happen. The query fails to execute: your database doesn't exist, so execute a series of CREATE statements to build it. The query succeeds but returns no rows or the release number is lower than expected: your database exists, but is out of date. You need to migrate from that release to the current release. Hopefully, you have a sequence of DROP, CREATE and ALTER statements to do this. The query succeeds, and the release number is the expected value. Do nothing more, your database is configured correctly.
5
13
0
I have created a Python module that creates and populates several SQLite tables. Now, I want to use it in a program but I don't really know how to call it properly. All the tutorials I've found are essentially "inline", i.e. they walk through using SQLite in a linear fashion rather than how to actually use it in production. What I'm trying to do is have a method check to see if the database is already created. If so, then I can use it. If not, an exception is raised and the program will create the database. (Or use if/else statements, whichever is better). I created a test script to see if my logic is correct but it's not working. When I create the try statement, it just creates a new database rather than checking if one already exists. The next time I run the script, I get an error that the table already exists, even if I tried catching the exception. (I haven't used try/except before but figured this is a good time to learn). Are there any good tutorials for using SQLite operationally or any suggestions on how to code this? I've looked through the pysqlite tutorial and others I found but they don't address this.
Using SQLite in a Python program
1
1
0
31,269
211,501
2008-10-17T09:02:00.000
13
0
0
0
python,exception,sqlite
211,534
8
true
0
0
AFAIK an SQLITE database is just a file. To check if the database exists, check for file existence. When you open a SQLITE database it will automatically create one if the file that backs it up is not in place. If you try and open a file as a sqlite3 database that is NOT a database, you will get this: "sqlite3.DatabaseError: file is encrypted or is not a database" so check to see if the file exists and also make sure to try and catch the exception in case the file is not a sqlite3 database
5
13
0
I have created a Python module that creates and populates several SQLite tables. Now, I want to use it in a program but I don't really know how to call it properly. All the tutorials I've found are essentially "inline", i.e. they walk through using SQLite in a linear fashion rather than how to actually use it in production. What I'm trying to do is have a method check to see if the database is already created. If so, then I can use it. If not, an exception is raised and the program will create the database. (Or use if/else statements, whichever is better). I created a test script to see if my logic is correct but it's not working. When I create the try statement, it just creates a new database rather than checking if one already exists. The next time I run the script, I get an error that the table already exists, even if I tried catching the exception. (I haven't used try/except before but figured this is a good time to learn). Are there any good tutorials for using SQLite operationally or any suggestions on how to code this? I've looked through the pysqlite tutorial and others I found but they don't address this.
Using SQLite in a Python program
1.2
1
0
31,269
211,536
2008-10-17T09:23:00.000
2
1
1
0
java,javascript,python,scripting-language
838,738
11
false
1
0
Short version Don’t use a scripting language! Instead focus on configurability (which is something that a non-programmer can do well). Longer version One oft-used argument in favour of having a scripting language is that it allows for lesser programmers to more trivial tasks. Don't belive this, it will not save you any time, since trivial tasks are already accomplished by real programmers in no time. Aim for configurability instead of scripting, and you will have a much lower risk of bleeding over complex algorithms and concepts into the incapable hands of game designers. :) Lack of hotswapping (edit-and-continue) would have been a reason to implement a scripting language in an MMOG (you don’t want to reload the whole game for a minor code change), but using Java, with built-in hotswap, you really have no reason for adding a scripting language on top. I have spent years pondering these questions; in the day I implemented a complete scripting language, IDE, VM, debugger, etc for an MMOG myself. Since, I have grown wiser. If you still choose to go down the infinitely crappy path of no return, keep the following in mind. Pick a mature language which has been around for a while. Auto testing, debugging and editing will suck bigtime until you make your own tools/plugins/start hacking around in the VM. To date, I have never seen a DSL that improved the situation (getting a more maintainable product). Myself, I integrated Python into my indie game engine, but eventually came to my senses and ripped it out. "Stackless Python" is just a way of saying "unmaintainable but fast". Please, anyone correct me if I'm wrong?
3
8
0
Me and some friends are writing a MORPG in Java, and we would like to use a scripting language to, eg. to create quests. We have non experience with scripting in Java. We have used Python, but we are very inexperienced with it. One of us also have used Javascript. What scripting language should we use? What scripting language should we not use?
Scripting in Java
0.036348
0
0
1,679
211,536
2008-10-17T09:23:00.000
0
1
1
0
java,javascript,python,scripting-language
211,883
11
false
1
0
I am a big fan of Python/Jython due to the clean syntax - which may suit you if you have some python experience. Otherwise Groovy which is based on Java syntax and may be an easier learning curve if most of your developers are Java guys. It also has the advantage of closer ties with the Java language and libraries. Beanshell is good if you have simple scripting in mind - it doesn't support classes. However I don't think it has had any support over the last few years (the JSR seemed to kill it off...) so is perhaps a bad choice if support is important to you.
3
8
0
Me and some friends are writing a MORPG in Java, and we would like to use a scripting language to, eg. to create quests. We have non experience with scripting in Java. We have used Python, but we are very inexperienced with it. One of us also have used Javascript. What scripting language should we use? What scripting language should we not use?
Scripting in Java
0
0
0
1,679
211,536
2008-10-17T09:23:00.000
9
1
1
0
java,javascript,python,scripting-language
215,096
11
false
1
0
I'm responsible for a fairly large hybrid Java/Jython system. We use java for core API development, then wire Java objects together using Jython. This is in a scientific computing environment where we need to be able to put together ad-hoc data analysis scripts quickly. If I were starting this system from scratch today, I would not choose Jython as the scripting language. I like Python fine, but I frequently encounter awkward mismatches between the Python type system and the Java type system. For example, if you just want a hashtable, should you use a Python dictionary or a Java HashMap? The decision might be different depending on whether you are just using the data structure locally in Python code or passing it across the Java boundary. Jython does a certain amount of type coercion for you, but it's not perfect. It's annoying to even have to think about issues like this when the purpose of using a scripting language in the first place is to enhance your productivity. I assume JavaScript or JRuby would have similar issues. Today I would choose a scripting language that is specifically targeted to the JVM and leverages the Java type system. The obvious candidates are Groovy and Beanshell; Groovy seems to have been picking up momentum lately so I'd look most closely at it.
3
8
0
Me and some friends are writing a MORPG in Java, and we would like to use a scripting language to, eg. to create quests. We have non experience with scripting in Java. We have used Python, but we are very inexperienced with it. One of us also have used Javascript. What scripting language should we use? What scripting language should we not use?
Scripting in Java
1
0
0
1,679
213,483
2008-10-17T19:12:00.000
3
1
1
0
python,apache,webserver,mod-python
213,742
11
false
0
0
Its hard to give a definitive answer without knowing what kind of site you are working on and what kind of load you are expecting. Sub second performance may be a serious requirement or it may not. If you really need to save that last millisecond then you absolutely need to keep your arrays in memory. However as others have suggested it is more than likely that you don't and could get by with something else. Your usage pattern of the data in the array may affect what kinds of choices you make. You probably don't need access to the entire set of data from the array all at once so you could break your data up into smaller chunks and put those chunks in the cache instead of the one big lump. Depending on how often your array data needs to get updated you might make a choice between memcached, local db (berkley, sqlite, small mysql installation, etc) or a remote db. I'd say memcached for fairly frequent updates. A local db for something in the frequency of hourly and remote for the frequency of daily. One thing to consider also is what happens after a cache miss. If 50 clients all of a sudden get a cache miss and all of them at the same time decide to start regenerating those expensive arrays your box(es) will quickly be reduced to 8086's. So you have to take in to consideration how you will handle that. Many articles out there cover how to recover from cache misses. Hope this is helpful.
3
13
0
I am looking for a python webserver which is multithreaded instead of being multi-process (as in case of mod_python for apache). I want it to be multithreaded because I want to have an in memory object cache that will be used by various http threads. My webserver does a lot of expensive stuff and computes some large arrays which needs to be cached in memory for future use to avoid recomputing. This is not possible in a multi-process web server environment. Storing this information in memcache is also not a good idea as the arrays are large and storing them in memcache would lead to deserialization of data coming from memcache apart from the additional overhead of IPC. I implemented a simple webserver using BaseHttpServer, it gives good performance but it gets stuck after a few hours time. I need some more matured webserver. Is it possible to configure apache to use mod_python under a thread model so that I can do some object caching?
A good multithreaded python webserver?
0.054491
0
0
12,249
213,483
2008-10-17T19:12:00.000
7
1
1
0
python,apache,webserver,mod-python
213,572
11
false
0
0
Consider reconsidering your design. Maintaining that much state in your webserver is probably a bad idea. Multi-process is a much better way to go for stability. Is there another way to share state between separate processes? What about a service? Database? Index? It seems unlikely that maintaining a huge array of data in memory and relying on a single multi-threaded process to serve all your requests is the best design or architecture for your app.
3
13
0
I am looking for a python webserver which is multithreaded instead of being multi-process (as in case of mod_python for apache). I want it to be multithreaded because I want to have an in memory object cache that will be used by various http threads. My webserver does a lot of expensive stuff and computes some large arrays which needs to be cached in memory for future use to avoid recomputing. This is not possible in a multi-process web server environment. Storing this information in memcache is also not a good idea as the arrays are large and storing them in memcache would lead to deserialization of data coming from memcache apart from the additional overhead of IPC. I implemented a simple webserver using BaseHttpServer, it gives good performance but it gets stuck after a few hours time. I need some more matured webserver. Is it possible to configure apache to use mod_python under a thread model so that I can do some object caching?
A good multithreaded python webserver?
1
0
0
12,249
213,483
2008-10-17T19:12:00.000
2
1
1
0
python,apache,webserver,mod-python
215,292
11
false
0
0
web.py has made me happy in the past. Consider checking it out. But it does sound like an architectural redesign might be the proper, though more expensive, solution.
3
13
0
I am looking for a python webserver which is multithreaded instead of being multi-process (as in case of mod_python for apache). I want it to be multithreaded because I want to have an in memory object cache that will be used by various http threads. My webserver does a lot of expensive stuff and computes some large arrays which needs to be cached in memory for future use to avoid recomputing. This is not possible in a multi-process web server environment. Storing this information in memcache is also not a good idea as the arrays are large and storing them in memcache would lead to deserialization of data coming from memcache apart from the additional overhead of IPC. I implemented a simple webserver using BaseHttpServer, it gives good performance but it gets stuck after a few hours time. I need some more matured webserver. Is it possible to configure apache to use mod_python under a thread model so that I can do some object caching?
A good multithreaded python webserver?
0.036348
0
0
12,249
213,838
2008-10-17T21:02:00.000
5
1
0
0
python,performance,trac
214,162
4
true
0
0
It's hard to say without knowing more about your setup, but one easy win is to make sure that Trac is running in something like mod_python, which keeps the Python runtime in memory. Otherwise, every HTTP request will cause Python to run, import all the modules, and then finally handle the request. Using mod_python (or FastCGI, whichever you prefer) will eliminate that loading and skip straight to the good stuff. Also, as your Trac database grows and you get more people using the site, you'll probably outgrow the default SQLite database. At that point, you should think about migrating the database to PostgreSQL or MySQL, because they'll be able to handle concurrent requests much faster.
2
3
0
I have noticed that my particular instance of Trac is not running quickly and has big lags. This is at the very onset of a project, so not much is in Trac (except for plugins and code loaded into SVN). Setup Info: This is via a SELinux system hosted by WebFaction. It is behind Apache, and connections are over SSL. Currently the .htpasswd file is what I use to control access. Are there any recommend ways to improve the performance of Trac?
How to improve Trac's performance
1.2
0
1
2,997
213,838
2008-10-17T21:02:00.000
3
1
0
0
python,performance,trac
215,084
4
false
0
0
We've had the best luck with FastCGI. Another critical factor was to only use https for authentication but use http for all other traffic -- I was really surprised how much that made a difference.
2
3
0
I have noticed that my particular instance of Trac is not running quickly and has big lags. This is at the very onset of a project, so not much is in Trac (except for plugins and code loaded into SVN). Setup Info: This is via a SELinux system hosted by WebFaction. It is behind Apache, and connections are over SSL. Currently the .htpasswd file is what I use to control access. Are there any recommend ways to improve the performance of Trac?
How to improve Trac's performance
0.148885
0
1
2,997
214,536
2008-10-18T03:56:00.000
1
0
0
0
python,templating
215,700
7
false
1
0
I've played both roles and at heart I prefer more of a programmer's templating language. However, I freelance for a few graphic designers doing the "heavy lifting" backed and db programming and can tell you that I've had the best luck with XML templating languages (SimpleTAL, Genshi, etc). When I'm trying to be web designer friendly I look for something that can be loaded into Dreamweaver and see results. This allows me to provide all the hooks in a template and let the designer tweak it without worrying about breaking what I've already written. It allows us to share the code and work better together where we're both comfortable with the format. If the designer codes without a WYSIWYG editor, I think you're options are less limited and you could go with your own personal favorite.
1
5
0
What are some good templating engines for web designers? I definitely have my preferences as to what I'd prefer to work with as a programmer. But web designers seem to have a different way of thinking about things and thus may prefer a different system. So: Web designers: what templating engine do you prefer to work with? programmers: what templating engines have you worked with that made working with web designers easy?
Python templates for web designers
0.028564
0
0
1,891