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
875,228
2009-05-17T19:00:00.000
2
0
1
0
python,file-io,csv,multidimensional-array,fileparsing
875,525
5
false
0
0
I'm looking for a simple solution using Python to store data as a flat file, such that each line is a string representation of an array that can be easily parsed. Is the data only ever going to be parsed by Python programs? If not, then I'd avoid pickle et al (shelve and marshal) since they're very Python specific. JSON and YAML have the important advantage that parsers are easily available for most any language.
1
3
1
I'm looking for a simple solution using Python to store data as a flat file, such that each line is a string representation of an array that can be easily parsed. I'm sure python has library for doing such a task easily but so far all the approaches I have found seemed like it would have been sloppy to get it to work and I'm sure there is a better approach. So far I've tried: the array.toFile() method but couldn't figure out how to get it to work with nested arrays of strings, it seemed geared towards integer data. Lists and sets do not have a toFile method built in, so I would have had to parse and encode it manually. CSV seemed like a good approach but this would also require manually parsing it, and did not allow me to simply append new lines at the end - so any new calls the the CSVWriter would overwrite the file existing data. I'm really trying to avoid using databases (maybe SQLite but it seems a bit overkill) because I'm trying to develop this to have no software prerequisites besides Python.
Simple data storing in Python
0.07983
0
0
5,460
875,476
2009-05-17T20:54:00.000
1
0
1
0
python,audio
877,551
6
false
1
0
You will need to come up with some threshold value of a minimum number of consecutive zeros before you cut them. Otherwise you'll be removing perfectly valid zeros from the middle of normal audio data. You can iterate through the wave file, copying any non-zero values, and buffering up zero values. When you're buffering zeroes and eventually come across the next non-zero, if the buffer has fewer samples that the threshold, copy them over, otherwise discard it. Python is not a great tool for this sort of task though. :(
1
4
0
Between each word in the wav file I have full silence (I checked with Hex workshop and silence is represented with 0's). How can I cut the non-silence sound? I'm programming using python. Thanks!
editing a wav files using python
0.033321
0
0
25,153
876,107
2009-05-18T03:15:00.000
3
0
0
0
python,performance,matplotlib,pyqt
876,151
1
true
0
1
Yes, loading the module takes place at the line where the import statement is. If you create your QApplication and show your splash screen before that, you should be able to do what you want -- also you need to call QApplication.processEvents() whenever you need the splash screen to update with a new message.
1
4
0
My PyQt application that uses matplotlib takes several seconds to load for the first time, even on a fast machine (the second load time is much shorter as the DLLs are kept in memory by Windows). I'm wondering whether it's feasible to show a splash screen while the matplotlib library is being loaded. Where does the actual loading take place - is it when the from line is executed? If so, how can I make this line execute during the splash screen and still be able to use the module throughout the code? A related dilemma is how to test this - can I ask Windows to load the DLLs for every execution and not cache them?
PyQt: splash screen while loading "heavy" libraries
1.2
0
0
3,080
876,258
2009-05-18T04:34:00.000
0
0
1
0
python,encryption,aes
876,304
2
false
0
0
To properly encrypt data, you need more than just an encryption algorithm. It's probably best you find a complete library with documentation showing how to do things properly, if you absolutely must do it yourself. Encryption alone is not sufficient. How are you generating keys? What mode of operation are you using? Are you using a MAC on the data? Straight AES in ECB mode leaks information. Without a MAC, even though the data is encrypted, an attacker can still tamper with your data.
1
0
0
I want to know is there any python 3.0 supported library for encryption. To encrypt files of 128 bits of data??
is there any AES encryption python library that will work well with python 3.0?
0
0
0
1,070
877,033
2009-05-18T10:13:00.000
2
0
0
1
python,webserver,simplehttpserver
22,310,248
3
false
0
0
Best way is to make your own local server by using command prompt. Make a new folder say Project Make a new folder inside project & name it as "cgi-bin"(without quotes) Paste your .py file inside the cgi-bin folder Open cmd and change to the directory from which you want to run the server and type "python -m CGIHTTPServer"(without quotes) Minimize the cmd window & open your browser and type "localhost:8000/cgi-bin/yourpythonfilename.py"(without quotes).
1
18
0
I'm looking to use a local webserver to run a series of python scripts for the user. For various unavoidable reasons, the python script must run locally, not on a server. As a result, I'll be using HTML+browser as the UI, which I'm comfortable with, for the front end. I've been looking, therefore, for a lightweight web server that can execute python scripts, sitting in the background on a machine, ideally as a Windows service. Security and extensibility are not high priorities as it's all running internally on a small network. Should I run a native python webserver as a Windows service (in which case, how)? Or is it just as easy to install Apache onto the user's machine and run as CGI? Since this is all local, performance is not an issue either. Or am I missing something obvious?
How can I create an local webserver for my python scripts?
0.132549
0
0
25,839
878,143
2009-05-18T14:56:00.000
4
0
0
0
c#,java,python
878,154
6
false
0
0
What's wrong with FTP? The protocol supports reusability and there are lots and lots of clients.
3
6
0
I am in the design phase of a file upload service that allows users to upload very large zip files to our server as well as updates our database with the data. Since the files are large (About 300mb) we want to allow the user to limit the amount of bandwidth they want to use for uploading. They should also be able to pause and resume the transfer, and it should recover from a system reboot. The user also needs to be authenticated in our MSSQL database to ensure that they have permission to upload the file and make changes to our database. My question is, what is the best technology to do this? We would like to minimize the amount of development required, but the only thing that I can think of now that would allow us to do this would be to create a client and server app from scratch in something like python, java or c#. Is there an existing technology available that will allow us to do this?
Resumable File Upload
0.132549
1
0
3,014
878,143
2009-05-18T14:56:00.000
0
0
0
0
c#,java,python
878,160
6
false
0
0
On client side, flash; On server side, whatever (it wouldn't make any difference). No existing technologies (except for using FTP or something).
3
6
0
I am in the design phase of a file upload service that allows users to upload very large zip files to our server as well as updates our database with the data. Since the files are large (About 300mb) we want to allow the user to limit the amount of bandwidth they want to use for uploading. They should also be able to pause and resume the transfer, and it should recover from a system reboot. The user also needs to be authenticated in our MSSQL database to ensure that they have permission to upload the file and make changes to our database. My question is, what is the best technology to do this? We would like to minimize the amount of development required, but the only thing that I can think of now that would allow us to do this would be to create a client and server app from scratch in something like python, java or c#. Is there an existing technology available that will allow us to do this?
Resumable File Upload
0
1
0
3,014
878,143
2009-05-18T14:56:00.000
0
0
0
0
c#,java,python
30,990,243
6
false
0
0
I'm surprised no one has mentioned torrent files. They can also be packaged into a script that then triggers something to execute.
3
6
0
I am in the design phase of a file upload service that allows users to upload very large zip files to our server as well as updates our database with the data. Since the files are large (About 300mb) we want to allow the user to limit the amount of bandwidth they want to use for uploading. They should also be able to pause and resume the transfer, and it should recover from a system reboot. The user also needs to be authenticated in our MSSQL database to ensure that they have permission to upload the file and make changes to our database. My question is, what is the best technology to do this? We would like to minimize the amount of development required, but the only thing that I can think of now that would allow us to do this would be to create a client and server app from scratch in something like python, java or c#. Is there an existing technology available that will allow us to do this?
Resumable File Upload
0
1
0
3,014
879,218
2009-05-18T18:53:00.000
2
0
1
0
python
879,227
5
false
1
0
Not sure what you mean. For development First choice: idle -- you already have it. Second choice: Komodo Edit -- very easy to use, but not as directly interactive as idle. For deploying applications, that depends on your application. If you're building desktop applications or web applications, you still use similar tools. I prefer using Komodo Edit for big things (either desktop or web) because it's a nice IDE. What are you asking about? Development tools or final deployment of a finished product?
2
3
0
I'm looking to get up to speed on Python, is it worth working locally via the ActivePython interface, then progressing to a website that supports one of the standard frameworks (Django or Pylons) OR utilize the Google Apps environment? I want to stay as interactive as possible - making feedback/learning easier.
Python learning environment
0.07983
0
0
536
879,218
2009-05-18T18:53:00.000
2
0
1
0
python
879,231
5
false
1
0
I would just start locally. Django and Pylons add another layer of complexity to the edit/feedback loop. Unless your primary focus is to make python websites, just stick with an editor and the console.
2
3
0
I'm looking to get up to speed on Python, is it worth working locally via the ActivePython interface, then progressing to a website that supports one of the standard frameworks (Django or Pylons) OR utilize the Google Apps environment? I want to stay as interactive as possible - making feedback/learning easier.
Python learning environment
0.07983
0
0
536
880,917
2009-05-19T04:03:00.000
15
0
0
0
python
880,940
8
true
0
0
Google App Engine has excellent support for developing -- and especially for deploying -- web applications in Python (with several possible frameworks, of which Django may be the most suitable one for "relative amateurs"). Apart from web apps, Blender lets you use Python for 3D graphics, Poser for apps involving moving human-like figures, SPSS for statistics, scipy and many other tools included in Enthought's distribution support Python use in scientific programming and advanced visualization, etc, etc -- the sky's the limit.
4
2
0
What are some applications for Python that relative amateur programmers can get into? For example, Ruby has Rails for building web applications. What are some cool applications of Python? Thanks.
Applications of Python
1.2
0
0
1,769
880,917
2009-05-19T04:03:00.000
5
0
0
0
python
880,935
8
false
0
0
"cool" is a state of mind. Hence cool applications depends on your definition of cool. A Ant colony simulation is cool, if you want to implement the theory. Python, with its own and 3rd party libraries (batteries) has been applied in possibly all domains of day to day programming. My advise is, decide on the cool app you want to write and then see, what Python has to offer in that domain. If you are sufficiently satisfied, you can start coding. Good Luck!
4
2
0
What are some applications for Python that relative amateur programmers can get into? For example, Ruby has Rails for building web applications. What are some cool applications of Python? Thanks.
Applications of Python
0.124353
0
0
1,769
880,917
2009-05-19T04:03:00.000
0
0
0
0
python
880,938
8
false
0
0
Python is a general purpose programming language much like Ruby. It can be used for systems programming, embedded programming, desktop programming, and web programming. In short, it has about as much potential for "cool" projects as any other general purpose language.
4
2
0
What are some applications for Python that relative amateur programmers can get into? For example, Ruby has Rails for building web applications. What are some cool applications of Python? Thanks.
Applications of Python
0
0
0
1,769
880,917
2009-05-19T04:03:00.000
0
0
0
0
python
881,038
8
false
0
0
Probably not the most general purpose example, but I learned Python when AutoDesk Maya adopted it as a secondary programming language to complement MEL (Maya Expression Language). By comparison, it was a god-sent.
4
2
0
What are some applications for Python that relative amateur programmers can get into? For example, Ruby has Rails for building web applications. What are some cool applications of Python? Thanks.
Applications of Python
0
0
0
1,769
880,918
2009-05-19T04:03:00.000
10
0
1
1
python,redirect,io
880,929
5
false
0
0
Easiest is os.system("the.exe -a >thefile.txt"), but there are many other ways, for example with the subprocess module in the standard library.
1
18
0
In a script , I want to run a .exe with some command line parameters as "-a",and then redirect the standard output of the program to a file? How can I implement that?
How to redirect the output of .exe to a file in python?
1
0
0
15,233
881,332
2009-05-19T07:00:00.000
2
0
0
0
python,sockets
881,349
1
false
0
0
111 means the listener is down/not accepting connections - restart the Windows app that should be listening for connections, or disconnect any already-bound clients.
1
0
0
Nice to meet you. A socket makes a program in Python by Linux (the transmission of a message) ⇒ Windows (the reception), b ut the following errors occur and cannot connect now. Linux, Windows are network connection together, and there is the authority to cut. socket.error: (111, 'Connection refused') Could you help me!?
Error occurs when I connect with socket in Python
0.379949
0
1
619
881,517
2009-05-19T08:11:00.000
3
0
0
0
python,sqlalchemy
890,202
4
false
1
0
For a user login and basic permission tokens in a simple web application I will definitely store that in a cookie-based session. It's true that a few SELECTs per request is not a big deal at all, but then again if you can get some/all of your web requests to execute from cached data with no DB hits at all, that just adds that much more scalability to an app which is planning on receiving a lot of load. The issue of the user token being changed on the database is handled in two ways. One is, ignore it - for a lot of use cases its not that big a deal for the user to log out and log back in again to get at new permissions that have been granted elsewhere (witness unix as an example). The other is that all mutations of the user row are filtered through a method that also resets the state within the cookie-based session, but this is only effective if the user him/herself is the one initiating the changes through the browser interface. If OTOH neither of the above use cases apply to you, then you probably need to stick with a little bit of database access built into every request.
4
0
0
I'm currently working with a web application written in Python (and using SQLAlchemy). In order to handle authentication, the app first checks for a user ID in the session, and providing it exists, pulls that whole user record out of the database and stores it for the rest of that request. Another query is also run to check the permissions of the user it has stored. I'm fairly new to the web application development world, but from my understanding, hitting the database for something like this on every request isn't efficient. Or is this considered a normal thing to do? The only thing I've thought of so far is pulling up this data once, and storing what's relevant (most of the data isn't even required on every request). However, this brings up the problem of what's supposed to happen if this user record happens to be removed in the interim. Any ideas on how best to manage this?
SQLAlchemy - Database hits on every request?
0.148885
1
0
967
881,517
2009-05-19T08:11:00.000
1
0
0
0
python,sqlalchemy
881,535
4
false
1
0
It's a Database, so often it's fairly common to "hit" the Database to pull the required data. You can reduce single queries if you build up Joins or Stored Procedures.
4
0
0
I'm currently working with a web application written in Python (and using SQLAlchemy). In order to handle authentication, the app first checks for a user ID in the session, and providing it exists, pulls that whole user record out of the database and stores it for the rest of that request. Another query is also run to check the permissions of the user it has stored. I'm fairly new to the web application development world, but from my understanding, hitting the database for something like this on every request isn't efficient. Or is this considered a normal thing to do? The only thing I've thought of so far is pulling up this data once, and storing what's relevant (most of the data isn't even required on every request). However, this brings up the problem of what's supposed to happen if this user record happens to be removed in the interim. Any ideas on how best to manage this?
SQLAlchemy - Database hits on every request?
0.049958
1
0
967
881,517
2009-05-19T08:11:00.000
3
0
0
0
python,sqlalchemy
882,021
4
false
1
0
"hitting the database for something like this on every request isn't efficient." False. And, you've assumed that there's no caching, which is also false. Most ORM layers are perfectly capable of caching rows, saving some DB queries. Most RDBMS's have extensive caching, resulting in remarkably fast responses to common queries. All ORM layers will use consistent SQL, further aiding the database in optimizing the repetitive operations. (Specifically, the SQL statement is cached, saving parsing and planning time.) " Or is this considered a normal thing to do?" True. Until you can prove that your queries are the slowest part of your application, don't worry. Build something that actually works. Then optimize the part that you can prove is the bottleneck.
4
0
0
I'm currently working with a web application written in Python (and using SQLAlchemy). In order to handle authentication, the app first checks for a user ID in the session, and providing it exists, pulls that whole user record out of the database and stores it for the rest of that request. Another query is also run to check the permissions of the user it has stored. I'm fairly new to the web application development world, but from my understanding, hitting the database for something like this on every request isn't efficient. Or is this considered a normal thing to do? The only thing I've thought of so far is pulling up this data once, and storing what's relevant (most of the data isn't even required on every request). However, this brings up the problem of what's supposed to happen if this user record happens to be removed in the interim. Any ideas on how best to manage this?
SQLAlchemy - Database hits on every request?
0.148885
1
0
967
881,517
2009-05-19T08:11:00.000
2
0
0
0
python,sqlalchemy
882,171
4
false
1
0
You are basically talking about caching data as a performance optimization. As always, premature optimization is a bad idea. It's hard to know where the bottlenecks are beforehand, even more so if the application domain is new to you. Optimization adds complexity and if you optimize the wrong things, you not only have wasted the effort, but have made the necessary optimizations harder. Requesting user data usually is usually a pretty trivial query. You can build yourself a simple benchmark to see what kind of overhead it will introduce. If it isn't a significant percentage of your time-budget, just leave it be. If you still want to cache the data on the application server then you have to come up with a cache invalidation scheme. Possible schemes are to check for changes from the database. If you don't have a lot of data to cache, this really isn't significantly more efficient than just reloading it. Another option is to just time out cached data. This is a good option if instant visibility of changes isn't important. Another option is to actively invalidate caches on changes. This depends on whether you only modify the database through your application and if you have a single application server or a clustered solution.
4
0
0
I'm currently working with a web application written in Python (and using SQLAlchemy). In order to handle authentication, the app first checks for a user ID in the session, and providing it exists, pulls that whole user record out of the database and stores it for the rest of that request. Another query is also run to check the permissions of the user it has stored. I'm fairly new to the web application development world, but from my understanding, hitting the database for something like this on every request isn't efficient. Or is this considered a normal thing to do? The only thing I've thought of so far is pulling up this data once, and storing what's relevant (most of the data isn't even required on every request). However, this brings up the problem of what's supposed to happen if this user record happens to be removed in the interim. Any ideas on how best to manage this?
SQLAlchemy - Database hits on every request?
0.099668
1
0
967
881,536
2009-05-19T08:17:00.000
1
0
0
0
python,django,django-admin,field
881,692
2
false
1
0
Sure it's possible, but it will need some javascript. You'd want to bind an event to the keypress event on each field, and when it fires test the length of the text entered so far - if it matches, move the focus onto the next field.
1
0
0
I have an inline on a model with data with a fixed length, that has to be entered very fast, so I was thinking about a way of "tabbing" through fields automatically when the field is filled... Could that be possible?
Auto-tab between fields on Django admin site
0.099668
0
0
435
882,430
2009-05-19T12:24:00.000
3
1
0
1
python,cgi
882,444
6
false
0
0
Just use some good web framework e.g. django and you can have such URLs more than URLs you will have a better infrastructure, templates, db orm etc
1
13
0
Brand new to web design, using python. Got Apache up and running, test python script working in cgi-bin directory. Get valid results when I type in the URL explicitly: ".../cgi-bin/showenv.py" But I don't want the URL to look that way. Here at stackoverflow, for example, the URLs that display in my address bar never have the messy details showing the script that was used to run them. They're clean of cgi-bin, .py, etc. extensions. How do I do that? EDIT: Thanks for responses, every single one helpful, lots to learn. I'm going with URL Rewriting for now; example in the docs looks extremely close to what I actually want to do. But I'm committed to python, so will have to look at WSGI down the road.
How to hide "cgi-bin", ".py", etc from my URLs?
0.099668
0
0
10,240
883,348
2009-05-19T15:09:00.000
1
0
1
0
python,wxpython,multiprocessing
883,451
1
false
0
1
You could make two Queues between the two processes and have the second one delegate wx-related functionality to the first one (by pushing on the first queue the parameters of the task to perform, and waiting for the result on the second one).
1
0
0
I have a wxPython program with two processes: A primary and a secondary one (I'm using the multiprocessing module.) The primary one runs the wxPython GUI, the secondary one does not. However, there is something I would like to do from the secondary process: Given a string that describes a color, to check whether this would be legitimate color for wxPython. That means, whether I can create a wx.Pen(color_string) or not. How do I do this? (I tried making a wx.Pen and comparing its color to the null color, but that required to create a wx.App in the second process, and when I did create one the program raised an error in some special wxPython window.)
wxPython + multiprocessing: Checking if a color string is legitimate
0.197375
0
0
670
883,575
2009-05-19T15:49:00.000
0
0
0
0
python,django,django-models
883,645
4
false
1
0
It depends on where you want to use it. If you want to use it in your own templates, I would suggest to write a template-tag, that will do the ordering for you In it, you could use any sorting algorithm you want to use. In admin I do custom sorting by extending the templates to my needs and loading a template-tag as described above
2
39
0
How do you define a specific ordering in Django QuerySets? Specifically, if I have a QuerySet like so: ['a10', 'a1', 'a2']. Regular order (using Whatever.objects.order_by('someField')) will give me ['a1', 'a10', 'a2'], while I am looking for: ['a1', 'a2', 'a10']. What is the proper way to define my own ordering technique?
Custom ordering in Django
0
0
0
29,554
883,575
2009-05-19T15:49:00.000
37
0
0
0
python,django,django-models
889,445
4
false
1
0
@Jarret's answer (do the sort in Python) works great for simple cases. As soon as you have a large table and want to, say, pull only the first page of results sorted in a certain way, this approach breaks (you have to pull every single row from the database before you can do the sort). At that point I would look into adding a denormalized "sort" field which you populate from the "name" field at save-time, that you can sort on at the DB-level in the usual way.
2
39
0
How do you define a specific ordering in Django QuerySets? Specifically, if I have a QuerySet like so: ['a10', 'a1', 'a2']. Regular order (using Whatever.objects.order_by('someField')) will give me ['a1', 'a10', 'a2'], while I am looking for: ['a1', 'a2', 'a10']. What is the proper way to define my own ordering technique?
Custom ordering in Django
1
0
0
29,554
885,294
2009-05-19T22:13:00.000
5
0
0
0
python,keyboard,wxpython
885,307
1
true
0
1
That should happen automatically if the button has the wx.ID_OK id. If that's impossible then the wx.StdDialogButtonSizer.SetAffirmativeButton() method could be a solution (using the StdDialogButtonSizer class will help with correct button placement and positioning on the different platforms), and there is also wx.Button.SetDefault().
1
3
0
I am creating a custom wxPython dialog by subclassing wx.Dialog. When I press Enter while using it, (and while being focused on one of the form elements,) it just takes the focus to the next form element, while I want it to press the ok button. How do I solve this?
wxPython dialogs: "Enter" keyboard button would not "ok" the dialog
1.2
0
0
1,846
885,625
2009-05-20T00:03:00.000
0
0
1
0
python,database,dictionary
885,643
5
false
0
0
Here are three things you can try: Compress the pickled dictionary with zlib. pickle.dumps(dict).encode("zlib") Make your own serializing format (shouldn't be too hard). Load the data in a sqlite database.
2
0
0
I am building an application to distribute to fellow academics. The application will take three parameters that the user submits and output a list of dates and codes related to those events. I have been building this using a dictionary and intended to build the application so that the dictionary loaded from a pickle file when the application called for it. The parameters supplied by the user will be used to lookup the needed output. I selected this structure because I have gotten pretty comfortable with dictionaries and pickle files and I see this going out the door with the smallest learning curve on my part. There might be as many as two million keys in the dictionary. I have been satisfied with the performance on my machine with a reasonable subset. I have already thought through about how to break the dictionary apart if I have any performance concerns when the whole thing is put together. I am not really that worried about the amount of disk space on their machine as we are working with terabyte storage values. Having said all of that I have been poking around in the docs and am wondering if I need to invest some time to learn and implement an alternative data storage file. The only reason I can think of is if there is an alternative that could increase the lookup speed by a factor of three to five or more.
What is the least resource intense data structure to distribute with a Python Application
0
0
0
312
885,625
2009-05-20T00:03:00.000
2
0
1
0
python,database,dictionary
885,813
5
false
0
0
How much memory can your application reasonably use? Is this going to be running on each user's desktop, or will there just be one deployment somewhere? A python dictionary in memory can certainly cope with two million keys. You say that you've got a subset of the data; do you have the whole lot? Maybe you should throw the full dataset at it and see whether it copes. I just tested creating a two million record dictionary; the total memory usage for the process came in at about 200MB. If speed is your primary concern and you've got the RAM to spare, you're probably not going to do better than an in-memory python dictionary.
2
0
0
I am building an application to distribute to fellow academics. The application will take three parameters that the user submits and output a list of dates and codes related to those events. I have been building this using a dictionary and intended to build the application so that the dictionary loaded from a pickle file when the application called for it. The parameters supplied by the user will be used to lookup the needed output. I selected this structure because I have gotten pretty comfortable with dictionaries and pickle files and I see this going out the door with the smallest learning curve on my part. There might be as many as two million keys in the dictionary. I have been satisfied with the performance on my machine with a reasonable subset. I have already thought through about how to break the dictionary apart if I have any performance concerns when the whole thing is put together. I am not really that worried about the amount of disk space on their machine as we are working with terabyte storage values. Having said all of that I have been poking around in the docs and am wondering if I need to invest some time to learn and implement an alternative data storage file. The only reason I can think of is if there is an alternative that could increase the lookup speed by a factor of three to five or more.
What is the least resource intense data structure to distribute with a Python Application
0.07983
0
0
312
885,771
2009-05-20T01:22:00.000
5
0
0
0
php,python,mysql,ruby,migration
885,783
2
true
0
0
I believe MySQL only needs to alter metadata and references to the table's old name in stored procedures -- the number of records in the table should be irrelevant.
1
3
0
MySQL has a RENAME TABLE statemnt that will allow you to change the name of a table. The manual mentions The rename operation is done atomically, which means that no other session can access any of the tables while the rename is running The manual does not (to my knowedge) state how this renaming is accomplished. Is an entire copy of the table created, given a new name, and then the old table deleted? Or does MySQL do some magic behind the scenes to quickly rename the table? In other words, does the size of the table have an effect on how long the RENAME table statement will take to run. Are there other things that might cause the renaming of a block to significantly block?
How does MySQL's RENAME TABLE statment work/perform?
1.2
1
0
2,472
886,221
2009-05-20T05:07:00.000
6
0
0
0
python,django,web-applications,scalability
886,309
29
false
1
0
Note that if you're expecting 100K users per day, that are active for hours at a time (meaning max of 20K+ concurrent users), you're going to need A LOT of servers. SO has ~15,000 registered users, and most of them are probably not active daily. While the bulk of traffic comes from unregistered users, I'm guessing that very few of them stay on the site more than a couple minutes (i.e. they follow google search results then leave). For that volume, expect at least 30 servers ... which is still a rather heavy 1,000 concurrent users per server.
8
1,204
0
I'm building a web application with Django. The reasons I chose Django were: I wanted to work with free/open-source tools. I like Python and feel it's a long-term language, whereas regarding Ruby I wasn't sure, and PHP seemed like a huge hassle to learn. I'm building a prototype for an idea and wasn't thinking too much about the future. Development speed was the main factor, and I already knew Python. I knew the migration to Google App Engine would be easier should I choose to do so in the future. I heard Django was "nice". Now that I'm getting closer to thinking about publishing my work, I start being concerned about scale. The only information I found about the scaling capabilities of Django is provided by the Django team (I'm not saying anything to disregard them, but this is clearly not objective information...). My questions: What's the "largest" site that's built on Django today? (I measure size mostly by user traffic) Can Django deal with 100,000 users daily, each visiting the site for a couple of hours? Could a site like Stack Overflow run on Django?
Does Django scale?
1
0
0
203,038
886,221
2009-05-20T05:07:00.000
6
0
0
0
python,django,web-applications,scalability
33,579,299
29
false
1
0
I don't think the issue is really about Django scaling. I really suggest you look into your architecture that's what will help you with your scaling needs.If you get that wrong there is no point on how well Django performs. Performance != Scale. You can have a system that has amazing performance but does not scale and vice versa. Is your application database bound? If it is then your scale issues lay there as well. How are you planning on interacting with the database from Django? What happens when you database cannot process requests as fast as Django accepts them? What happens when your data outgrows one physical machine. You need to account for how you plan on dealing with those circumstances. Moreover, What happens when your traffic outgrows one app server? how you handle sessions in this case can be tricky, more often than not you would probably require a shared nothing architecture. Again that depends on your application. In short languages is not what determines scale, a language is responsible for performance(again depending on your applications, different languages perform differently). It is your design and architecture that makes scaling a reality. I hope it helps, would be glad to help further if you have questions.
8
1,204
0
I'm building a web application with Django. The reasons I chose Django were: I wanted to work with free/open-source tools. I like Python and feel it's a long-term language, whereas regarding Ruby I wasn't sure, and PHP seemed like a huge hassle to learn. I'm building a prototype for an idea and wasn't thinking too much about the future. Development speed was the main factor, and I already knew Python. I knew the migration to Google App Engine would be easier should I choose to do so in the future. I heard Django was "nice". Now that I'm getting closer to thinking about publishing my work, I start being concerned about scale. The only information I found about the scaling capabilities of Django is provided by the Django team (I'm not saying anything to disregard them, but this is clearly not objective information...). My questions: What's the "largest" site that's built on Django today? (I measure size mostly by user traffic) Can Django deal with 100,000 users daily, each visiting the site for a couple of hours? Could a site like Stack Overflow run on Django?
Does Django scale?
1
0
0
203,038
886,221
2009-05-20T05:07:00.000
4
0
0
0
python,django,web-applications,scalability
35,997,907
29
false
1
0
Even-though there have been a lot of great answers here, I just feel like pointing out, that nobody have put emphasis on.. It depends on the application If you application is light on writes, as in you are reading a lot more data from the DB than you are writing. Then scaling django should be fairly trivial, heck, it comes with some fairly decent output/view caching straight out of the box. Make use of that, and say, redis as a cache provider, put a load balancer in front of it, spin up n-instances and you should be able to deal with a VERY large amount of traffic. Now, if you have to do thousands of complex writes a second? Different story. Is Django going to be a bad choice? Well, not necessarily, depends on how you architect your solution really, and also, what your requirements are. Just my two cents :-)
8
1,204
0
I'm building a web application with Django. The reasons I chose Django were: I wanted to work with free/open-source tools. I like Python and feel it's a long-term language, whereas regarding Ruby I wasn't sure, and PHP seemed like a huge hassle to learn. I'm building a prototype for an idea and wasn't thinking too much about the future. Development speed was the main factor, and I already knew Python. I knew the migration to Google App Engine would be easier should I choose to do so in the future. I heard Django was "nice". Now that I'm getting closer to thinking about publishing my work, I start being concerned about scale. The only information I found about the scaling capabilities of Django is provided by the Django team (I'm not saying anything to disregard them, but this is clearly not objective information...). My questions: What's the "largest" site that's built on Django today? (I measure size mostly by user traffic) Can Django deal with 100,000 users daily, each visiting the site for a couple of hours? Could a site like Stack Overflow run on Django?
Does Django scale?
0.027579
0
0
203,038
886,221
2009-05-20T05:07:00.000
283
0
0
0
python,django,web-applications,scalability
887,363
29
false
1
0
We're doing load testing now. We think we can support 240 concurrent requests (a sustained rate of 120 hits per second 24x7) without any significant degradation in the server performance. That would be 432,000 hits per hour. Response times aren't small (our transactions are large) but there's no degradation from our baseline performance as the load increases. We're using Apache front-ending Django and MySQL. The OS is Red Hat Enterprise Linux (RHEL). 64-bit. We use mod_wsgi in daemon mode for Django. We've done no cache or database optimization other than to accept the defaults. We're all in one VM on a 64-bit Dell with (I think) 32Gb RAM. Since performance is almost the same for 20 or 200 concurrent users, we don't need to spend huge amounts of time "tweaking". Instead we simply need to keep our base performance up through ordinary SSL performance improvements, ordinary database design and implementation (indexing, etc.), ordinary firewall performance improvements, etc. What we do measure is our load test laptops struggling under the insane workload of 15 processes running 16 concurrent threads of requests.
8
1,204
0
I'm building a web application with Django. The reasons I chose Django were: I wanted to work with free/open-source tools. I like Python and feel it's a long-term language, whereas regarding Ruby I wasn't sure, and PHP seemed like a huge hassle to learn. I'm building a prototype for an idea and wasn't thinking too much about the future. Development speed was the main factor, and I already knew Python. I knew the migration to Google App Engine would be easier should I choose to do so in the future. I heard Django was "nice". Now that I'm getting closer to thinking about publishing my work, I start being concerned about scale. The only information I found about the scaling capabilities of Django is provided by the Django team (I'm not saying anything to disregard them, but this is clearly not objective information...). My questions: What's the "largest" site that's built on Django today? (I measure size mostly by user traffic) Can Django deal with 100,000 users daily, each visiting the site for a couple of hours? Could a site like Stack Overflow run on Django?
Does Django scale?
1
0
0
203,038
886,221
2009-05-20T05:07:00.000
2
0
0
0
python,django,web-applications,scalability
4,272,991
29
false
1
0
Spreading the tasks evenly, in short optimizing each and every aspect including DBs, Files, Images, CSS etc. and balancing the load with several other resources is necessary once your site/application starts growing. OR you make some more space for it to grow. Implementation of latest technologies like CDN, Cloud are must with huge sites. Just developing and tweaking an application won't give your the cent percent satisfation, other components also play an important role.
8
1,204
0
I'm building a web application with Django. The reasons I chose Django were: I wanted to work with free/open-source tools. I like Python and feel it's a long-term language, whereas regarding Ruby I wasn't sure, and PHP seemed like a huge hassle to learn. I'm building a prototype for an idea and wasn't thinking too much about the future. Development speed was the main factor, and I already knew Python. I knew the migration to Google App Engine would be easier should I choose to do so in the future. I heard Django was "nice". Now that I'm getting closer to thinking about publishing my work, I start being concerned about scale. The only information I found about the scaling capabilities of Django is provided by the Django team (I'm not saying anything to disregard them, but this is clearly not objective information...). My questions: What's the "largest" site that's built on Django today? (I measure size mostly by user traffic) Can Django deal with 100,000 users daily, each visiting the site for a couple of hours? Could a site like Stack Overflow run on Django?
Does Django scale?
0.013792
0
0
203,038
886,221
2009-05-20T05:07:00.000
5
0
0
0
python,django,web-applications,scalability
887,463
29
false
1
0
Another example is rasp.yandex.ru, Russian transport timetable service. Its attendance satisfies your requirements.
8
1,204
0
I'm building a web application with Django. The reasons I chose Django were: I wanted to work with free/open-source tools. I like Python and feel it's a long-term language, whereas regarding Ruby I wasn't sure, and PHP seemed like a huge hassle to learn. I'm building a prototype for an idea and wasn't thinking too much about the future. Development speed was the main factor, and I already knew Python. I knew the migration to Google App Engine would be easier should I choose to do so in the future. I heard Django was "nice". Now that I'm getting closer to thinking about publishing my work, I start being concerned about scale. The only information I found about the scaling capabilities of Django is provided by the Django team (I'm not saying anything to disregard them, but this is clearly not objective information...). My questions: What's the "largest" site that's built on Django today? (I measure size mostly by user traffic) Can Django deal with 100,000 users daily, each visiting the site for a couple of hours? Could a site like Stack Overflow run on Django?
Does Django scale?
0.034469
0
0
203,038
886,221
2009-05-20T05:07:00.000
5
0
0
0
python,django,web-applications,scalability
25,727,705
29
false
1
0
I develop high traffic sites using Django for the national broadcaster in Ireland. It works well for us. Developing a high performance site is more than about just choosing a framework. A framework will only be one part of a system that is as strong as it's weakest link. Using the latest framework 'X' won't solve your performance issues if the problem is slow database queries or a badly configured server or network.
8
1,204
0
I'm building a web application with Django. The reasons I chose Django were: I wanted to work with free/open-source tools. I like Python and feel it's a long-term language, whereas regarding Ruby I wasn't sure, and PHP seemed like a huge hassle to learn. I'm building a prototype for an idea and wasn't thinking too much about the future. Development speed was the main factor, and I already knew Python. I knew the migration to Google App Engine would be easier should I choose to do so in the future. I heard Django was "nice". Now that I'm getting closer to thinking about publishing my work, I start being concerned about scale. The only information I found about the scaling capabilities of Django is provided by the Django team (I'm not saying anything to disregard them, but this is clearly not objective information...). My questions: What's the "largest" site that's built on Django today? (I measure size mostly by user traffic) Can Django deal with 100,000 users daily, each visiting the site for a couple of hours? Could a site like Stack Overflow run on Django?
Does Django scale?
0.034469
0
0
203,038
886,221
2009-05-20T05:07:00.000
4
0
0
0
python,django,web-applications,scalability
26,828,032
29
false
1
0
The problem is not to know if django can scale or not. The right way is to understand and know which are the network design patterns and tools to put under your django/symfony/rails project to scale well. Some ideas can be : Multiplexing. Inversed proxy. Ex : Nginx, Varnish Memcache Session. Ex : Redis Clusterization on your project and db for load balancing and fault tolerance : Ex : Docker Use third party to store assets. Ex : Amazon S3 Hope it help a bit. This is my tiny rock to the mountain.
8
1,204
0
I'm building a web application with Django. The reasons I chose Django were: I wanted to work with free/open-source tools. I like Python and feel it's a long-term language, whereas regarding Ruby I wasn't sure, and PHP seemed like a huge hassle to learn. I'm building a prototype for an idea and wasn't thinking too much about the future. Development speed was the main factor, and I already knew Python. I knew the migration to Google App Engine would be easier should I choose to do so in the future. I heard Django was "nice". Now that I'm getting closer to thinking about publishing my work, I start being concerned about scale. The only information I found about the scaling capabilities of Django is provided by the Django team (I'm not saying anything to disregard them, but this is clearly not objective information...). My questions: What's the "largest" site that's built on Django today? (I measure size mostly by user traffic) Can Django deal with 100,000 users daily, each visiting the site for a couple of hours? Could a site like Stack Overflow run on Django?
Does Django scale?
0.027579
0
0
203,038
886,526
2009-05-20T07:07:00.000
1
0
0
1
python,django,shell
886,561
2
false
1
0
It is possible. Usually you will develop your application locally (where shell access is nice to have) and publish your work to your server. All you need for this is FTP access and some way to import a database dump from your development database (often hosters provide an installation of phpMyAdmin for this). python (I assume via mod_python) From my experience, you are most certainly wrong with that assumption. Many low-cost providers claim to support python but in fact provide only an outdated version that can be used with CGI scripts. This setup will have a pretty low performance for Django apps.
1
0
0
Is it possible to run django without shell access? My hoster supports the following for 5€/month: python (I assume via mod_python) mysql There is no shell nor cronjob support, which costs additional 10€/month, so I'm trying to avoid it. I know that Google Apps also work without shell access, but I assume that is possible because of their special configuration.
Django without shell access
0.099668
0
0
702
886,653
2009-05-20T07:44:00.000
1
1
0
0
python,cgi
886,956
3
false
0
0
The script is probably not killed silently; you just don't see the exception which python throws. I suggest to wrap the whole script in try-except and write any exception to a log file. This way, you can see what really happens. The logging module is your friend.
1
2
0
I have a python cgi script that accepts user uploads (via sys.stdin.read). After receiving the file (whether successfully or unsuccessfully), the script needs to do some cleanup. This works fine when upload finishes correctly, however if the user closes the client, the cgi script is silently killed on the server, and as a result no cleanup code gets executed. How can i force the script to always finish.
Making a python cgi script to finish gracefully
0.066568
0
0
1,833
886,895
2009-05-20T08:50:00.000
1
0
1
1
python,linux,runtime,sandbox,restriction
5,289,924
5
false
0
0
could you not just run as a user which has no access to anything but the scripts in that directory?
4
2
0
Is it possible to create an environment to safely run arbitrary Python scripts under Linux? Those scripts are supposed to be received from untrusted people and may be too large to check them manually. A very brute-force solution is to create a virtual machine and restore its initial state after every launch of an untrusted script. (Too expensive.) I wonder if it's possible to restrict Python from accessing the file system and interacting with other programs and so on.
Safe Python Environment in Linux
0.039979
0
0
920
886,895
2009-05-20T08:50:00.000
2
0
1
1
python,linux,runtime,sandbox,restriction
887,091
5
false
0
0
You could run jython and use the sandboxing mechanism from the JVM. The sandboxing in the JVM is very strong very well understood and more or less well documented. It will take some time to define exactly what you want to allow and what you dnt want to allow, but you should be able to get a very strong security from that ... On the other side, jython is not 100% compatible with cPython ...
4
2
0
Is it possible to create an environment to safely run arbitrary Python scripts under Linux? Those scripts are supposed to be received from untrusted people and may be too large to check them manually. A very brute-force solution is to create a virtual machine and restore its initial state after every launch of an untrusted script. (Too expensive.) I wonder if it's possible to restrict Python from accessing the file system and interacting with other programs and so on.
Safe Python Environment in Linux
0.07983
0
0
920
886,895
2009-05-20T08:50:00.000
4
0
1
1
python,linux,runtime,sandbox,restriction
887,104
5
false
0
0
There are 4 things you may try: As you already mentioned, using a virtual machine or some other form of virtualisation (perhaps solaris zones are lightweight enough?). If the script breaks the OS there then you don't care. Using chroot, which puts a shell session into a virtual root directory, separate from the main OS root directory. Using systrace. Think of this as a firewall for system calls. Using a "jail", which builds upon systrace, giving each jail it's own process table etc. Systrace has been compromised recently, so be aware of that.
4
2
0
Is it possible to create an environment to safely run arbitrary Python scripts under Linux? Those scripts are supposed to be received from untrusted people and may be too large to check them manually. A very brute-force solution is to create a virtual machine and restore its initial state after every launch of an untrusted script. (Too expensive.) I wonder if it's possible to restrict Python from accessing the file system and interacting with other programs and so on.
Safe Python Environment in Linux
0.158649
0
0
920
886,895
2009-05-20T08:50:00.000
4
0
1
1
python,linux,runtime,sandbox,restriction
886,945
5
true
0
0
Consider using a chroot jail. Not only is this very secure, well-supported and tested but it also applies to external applications you run from python.
4
2
0
Is it possible to create an environment to safely run arbitrary Python scripts under Linux? Those scripts are supposed to be received from untrusted people and may be too large to check them manually. A very brute-force solution is to create a virtual machine and restore its initial state after every launch of an untrusted script. (Too expensive.) I wonder if it's possible to restrict Python from accessing the file system and interacting with other programs and so on.
Safe Python Environment in Linux
1.2
0
0
920
887,557
2009-05-20T12:12:00.000
2
0
0
1
python,linux,file,date
887,652
5
false
0
0
I am not a UNIX expert, so maybe I'm wrong, but I think that UNIX (or Linux) don't store file creation time.
1
15
0
Can I change creation date of some file using Python in Linux?
Change file creation date
0.07983
0
0
23,873
888,100
2009-05-20T14:04:00.000
3
0
1
0
python,compiler-construction,interpreter,bytecode
1,189,344
6
false
0
0
Although there is a small efficiency aspect to it (you can store the bytecode on disk or in memory), its mostly engineering: it allows you separate parsing from interpreting. Parsers can often be nasty creatures, full of edge-cases and having to conform to esoteric rules like using just the right amount of lookahead and resolving shift-reduce problems. By contrast, interpreting is really simple: its just a big switch statement using the bytecode's opcode.
5
15
0
Why python compile the source to bytecode before interpreting? Why not interpret from the source directly?
Why python compile the source to bytecode before interpreting?
0.099668
0
0
4,515
888,100
2009-05-20T14:04:00.000
7
0
1
0
python,compiler-construction,interpreter,bytecode
888,116
6
false
0
0
Because interpretting from bytecode directly is faster. It avoids the need to do lexing, for one thing.
5
15
0
Why python compile the source to bytecode before interpreting? Why not interpret from the source directly?
Why python compile the source to bytecode before interpreting?
1
0
0
4,515
888,100
2009-05-20T14:04:00.000
8
0
1
0
python,compiler-construction,interpreter,bytecode
888,117
6
false
0
0
Because you can compile to a .pyc once and interpret from it many times. So if you're running a script many times you only have the overhead of parsing the source code once.
5
15
0
Why python compile the source to bytecode before interpreting? Why not interpret from the source directly?
Why python compile the source to bytecode before interpreting?
1
0
0
4,515
888,100
2009-05-20T14:04:00.000
38
0
1
0
python,compiler-construction,interpreter,bytecode
888,119
6
true
0
0
Nearly no interpreter really interprets code directly, line by line – it's simply too inefficient. Almost all interpreters use some intermediate representation which can be executed easily. Also, small optimizations can be performed on this intermediate code. Python furthermore stores this code which has a huge advantage for the next time this code gets executed: Python doesn't have to parse the code anymore; parsing is the slowest part in the compile process. Thus, a bytecode representation reduces execution overhead quite substantially.
5
15
0
Why python compile the source to bytecode before interpreting? Why not interpret from the source directly?
Why python compile the source to bytecode before interpreting?
1.2
0
0
4,515
888,100
2009-05-20T14:04:00.000
6
0
1
0
python,compiler-construction,interpreter,bytecode
888,159
6
false
0
0
Re-lexing and parsing the source code over and over, rather than doing it just once (most often on the first import), would obviously be a silly and pointless waste of effort.
5
15
0
Why python compile the source to bytecode before interpreting? Why not interpret from the source directly?
Why python compile the source to bytecode before interpreting?
1
0
0
4,515
889,045
2009-05-20T16:45:00.000
1
0
1
0
python,regex
889,083
4
false
0
0
You could replace all the {} instances with your replacement string (which would include the {{}} ones), and then replace the {{}} ones with a back-reference to itself (overwriting the first replace with the original data) -- then only the {} instances would have changed.
1
5
0
Long story short, I have two regex patterns. One pattern matches things that I want to replace, and the other pattern matches a special case of those patterns that should not be replace. For a simple example, imagine that the first one is "\{.*\}" and the second one is "\{\{.*\}\}". Then "{this}" should be replaced, but "{{this}}" should not. Is there an easy way to take a string and say "substitute all instances of the first string with "hello" so long as it is not matching the second string"? In other words, is there a way to make a regex that is "matches the first string but not the second" easily without modifying the first string? I know that I could modify my first regex by hand to never match instances of the second, but as the first regex gets more complex, that gets very difficult.
Substituting a regex only when it doesn't match another regex (Python)
0.049958
0
0
1,924
889,143
2009-05-20T17:12:00.000
1
0
1
0
python,regex
889,170
5
false
0
0
The regular expression should be like ^#[0-7]##$
2
2
0
I would like to intercept string starting with \*#\* followed by a number between 0 and 7 and ending with: ## so something like \*#\*0## but I could not find a regex for this
Python regular expression to match # followed by 0-7 followed by ##
0.039979
0
0
453
889,143
2009-05-20T17:12:00.000
1
0
1
0
python,regex
889,154
5
false
0
0
r'\#[0-7]\#\#'
2
2
0
I would like to intercept string starting with \*#\* followed by a number between 0 and 7 and ending with: ## so something like \*#\*0## but I could not find a regex for this
Python regular expression to match # followed by 0-7 followed by ##
0.039979
0
0
453
889,974
2009-05-20T20:08:00.000
1
0
0
0
python,sqlite,date
890,025
3
false
0
0
Even though the ".schema" indicates that the field is a date or timestamp field... the field is actually a string. You can format the string anyway you want. If memory serves... their is no validation at all.
1
0
0
At start you have a string 'DDMMYYYY HHMMSS' and I want at the end to insert the string in a date field in sqlite3 database. The program is made in python. How can I do that ?
Is it possible to format a date with sqlite3?
0.066568
1
0
359
890,128
2009-05-20T20:40:00.000
8
1
1
0
python,function,lambda,closures
890,156
26
false
0
0
Lambdas are deeply linked to functional programming style in general. The idea that you can solve problems by applying a function to some data, and merging the results, is what google uses to implement most of its algorithms. Programs written in functional programming style, are easily parallelized and hence are becoming more and more important with modern multi-core machines. So in short, NO you should not forget them.
6
971
0
I'm trying to figure out Python lambdas. Is lambda one of those "interesting" language items that in real life should be forgotten? I'm sure there are some edge cases where it might be needed, but given the obscurity of it, the potential of it being redefined in future releases (my assumption based on the various definitions of it) and the reduced coding clarity - should it be avoided? This reminds me of overflowing (buffer overflow) of C types - pointing to the top variable and overloading to set the other field values. It feels like sort of a techie showmanship but maintenance coder nightmare.
How are lambdas useful?
1
0
0
576,496
890,128
2009-05-20T20:40:00.000
6
1
1
0
python,function,lambda,closures
890,217
26
false
0
0
I'm just beginning Python and ran head first into Lambda- which took me a while to figure out. Note that this isn't a condemnation of anything. Everybody has a different set of things that don't come easily. Is lambda one of those 'interesting' language items that in real life should be forgotten? No. I'm sure there are some edge cases where it might be needed, but given the obscurity of it, It's not obscure. The past 2 teams I've worked on, everybody used this feature all the time. the potential of it being redefined in future releases (my assumption based on the various definitions of it) I've seen no serious proposals to redefine it in Python, beyond fixing the closure semantics a few years ago. and the reduced coding clarity - should it be avoided? It's not less clear, if you're using it right. On the contrary, having more language constructs available increases clarity. This reminds me of overflowing (buffer overflow) of C types - pointing to the top variable and overloading to set the other field values...sort of a techie showmanship but maintenance coder nightmare.. Lambda is like buffer overflow? Wow. I can't imagine how you're using lambda if you think it's a "maintenance nightmare".
6
971
0
I'm trying to figure out Python lambdas. Is lambda one of those "interesting" language items that in real life should be forgotten? I'm sure there are some edge cases where it might be needed, but given the obscurity of it, the potential of it being redefined in future releases (my assumption based on the various definitions of it) and the reduced coding clarity - should it be avoided? This reminds me of overflowing (buffer overflow) of C types - pointing to the top variable and overloading to set the other field values. It feels like sort of a techie showmanship but maintenance coder nightmare.
How are lambdas useful?
1
0
0
576,496
890,128
2009-05-20T20:40:00.000
26
1
1
0
python,function,lambda,closures
890,151
26
false
0
0
Pretty much anything you can do with lambda you can do better with either named functions or list and generator expressions. Consequently, for the most part you should just one of those in basically any situation (except maybe for scratch code written in the interactive interpreter).
6
971
0
I'm trying to figure out Python lambdas. Is lambda one of those "interesting" language items that in real life should be forgotten? I'm sure there are some edge cases where it might be needed, but given the obscurity of it, the potential of it being redefined in future releases (my assumption based on the various definitions of it) and the reduced coding clarity - should it be avoided? This reminds me of overflowing (buffer overflow) of C types - pointing to the top variable and overloading to set the other field values. It feels like sort of a techie showmanship but maintenance coder nightmare.
How are lambdas useful?
1
0
0
576,496
890,128
2009-05-20T20:40:00.000
2
1
1
0
python,function,lambda,closures
890,192
26
false
0
0
Lambda is a procedure constructor. You can synthesize programs at run-time, although Python's lambda is not very powerful. Note that few people understand that kind of programming.
6
971
0
I'm trying to figure out Python lambdas. Is lambda one of those "interesting" language items that in real life should be forgotten? I'm sure there are some edge cases where it might be needed, but given the obscurity of it, the potential of it being redefined in future releases (my assumption based on the various definitions of it) and the reduced coding clarity - should it be avoided? This reminds me of overflowing (buffer overflow) of C types - pointing to the top variable and overloading to set the other field values. It feels like sort of a techie showmanship but maintenance coder nightmare.
How are lambdas useful?
0.015383
0
0
576,496
890,128
2009-05-20T20:40:00.000
5
1
1
0
python,function,lambda,closures
890,997
26
false
0
0
I started reading David Mertz's book today 'Text Processing in Python.' While he has a fairly terse description of Lambda's the examples in the first chapter combined with the explanation in Appendix A made them jump off the page for me (finally) and all of a sudden I understood their value. That is not to say his explanation will work for you and I am still at the discovery stage so I will not attempt to add to these responses other than the following: I am new to Python I am new to OOP Lambdas were a struggle for me Now that I read Mertz, I think I get them and I see them as very useful as I think they allow a cleaner approach to programming. He reproduces the Zen of Python, one line of which is Simple is better than complex. As a non-OOP programmer reading code with lambdas (and until last week list comprehensions) I have thought-This is simple?. I finally realized today that actually these features make the code much more readable, and understandable than the alternative-which is invariably a loop of some sort. I also realized that like financial statements-Python was not designed for the novice user, rather it is designed for the user that wants to get educated. I can't believe how powerful this language is. When it dawned on me (finally) the purpose and value of lambdas I wanted to rip up about 30 programs and start over putting in lambdas where appropriate.
6
971
0
I'm trying to figure out Python lambdas. Is lambda one of those "interesting" language items that in real life should be forgotten? I'm sure there are some edge cases where it might be needed, but given the obscurity of it, the potential of it being redefined in future releases (my assumption based on the various definitions of it) and the reduced coding clarity - should it be avoided? This reminds me of overflowing (buffer overflow) of C types - pointing to the top variable and overloading to set the other field values. It feels like sort of a techie showmanship but maintenance coder nightmare.
How are lambdas useful?
0.038443
0
0
576,496
890,128
2009-05-20T20:40:00.000
11
1
1
0
python,function,lambda,closures
3,961,969
26
false
0
0
As stated above, the lambda operator in Python defines an anonymous function, and in Python functions are closures. It is important not to confuse the concept of closures with the operator lambda, which is merely syntactic methadone for them. When I started in Python a few years ago, I used lambdas a lot, thinking they were cool, along with list comprehensions. However, I wrote and have to maintain a big website written in Python, with on the order of several thousand function points. I've learnt from experience that lambdas might be OK to prototype things with, but offer nothing over inline functions (named closures) except for saving a few key-stokes, or sometimes not. Basically this boils down to several points: it is easier to read software that is explicitly written using meaningful names. Anonymous closures by definition cannot have a meaningful name, as they have no name. This brevity seems, for some reason, to also infect lambda parameters, hence we often see examples like lambda x: x+1 it is easier to reuse named closures, as they can be referred to by name more than once, when there is a name to refer to them by. it is easier to debug code that is using named closures instead of lambdas, because the name will appear in tracebacks, and around the error. That's enough reason to round them up and convert them to named closures. However, I hold two other grudges against anonymous closures. The first grudge is simply that they are just another unnecessary keyword cluttering up the language. The second grudge is deeper and on the paradigm level, i.e. I do not like that they promote a functional-programming style, because that style is less flexible than the message passing, object oriented or procedural styles, because the lambda calculus is not Turing-complete (luckily in Python, we can still break out of that restriction even inside a lambda). The reasons I feel lambdas promote this style are: There is an implicit return, i.e. they seem like they 'should' be functions. They are an alternative state-hiding mechanism to another, more explicit, more readable, more reusable and more general mechanism: methods. I try hard to write lambda-free Python, and remove lambdas on sight. I think Python would be a slightly better language without lambdas, but that's just my opinion.
6
971
0
I'm trying to figure out Python lambdas. Is lambda one of those "interesting" language items that in real life should be forgotten? I'm sure there are some edge cases where it might be needed, but given the obscurity of it, the potential of it being redefined in future releases (my assumption based on the various definitions of it) and the reduced coding clarity - should it be avoided? This reminds me of overflowing (buffer overflow) of C types - pointing to the top variable and overloading to set the other field values. It feels like sort of a techie showmanship but maintenance coder nightmare.
How are lambdas useful?
1
0
0
576,496
890,827
2009-05-21T00:00:00.000
0
0
1
1
python,version,installation
891,966
4
false
0
0
You can also use the Fink package manager and simply to "fink install python2.3". If you need Python 2.3 to be your default, you can simply change /sw/bin/python and /sw/bin/pydoc to point to the version you want (they sit in /sw/bin/).
2
2
0
I have Mac OS X 10.5.7 with Python 2.5. I need to test a package I am working on with Python 2.3 for compatibility. I don't want to downgrade my whole system so is there a way to do an install of Python 2.3 that does not change the system python?
Install older versions of Python for testing on Mac OS X
0
0
0
5,880
890,827
2009-05-21T00:00:00.000
0
0
1
1
python,version,installation
892,087
4
false
0
0
One alternative is to use a virtual machine. With something like VMWare Fusion or Virtualbox you could install a complete Linux system with Python2.3, and do your testing there. The advantage is that it would be completely sand-boxed, so wouldn't affect your main system at all.
2
2
0
I have Mac OS X 10.5.7 with Python 2.5. I need to test a package I am working on with Python 2.3 for compatibility. I don't want to downgrade my whole system so is there a way to do an install of Python 2.3 that does not change the system python?
Install older versions of Python for testing on Mac OS X
0
0
0
5,880
891,934
2009-05-21T08:46:00.000
3
1
0
0
python,django,e-commerce,satchmo
901,050
1
true
1
0
It looks like the satchmo_cart_details_query signal is the way to go about doing this. It allows you to add a price change value (in my case, donation amount) to a cart item I'll post the full solution if anyone is interested
1
2
0
Can anyone share some pointers on building a Donations module for Satchmo? I'm comfortable customizing Satchmo's product models etc but unable to find anything related to Donations I realize it's possible to create a Donations virtual product but as far as I can tell this still requires setting the amount beforehand ($5, $10 etc). I want users to be able to donate arbitrary amounts
Satchmo donations
1.2
0
0
253
892,196
2009-05-21T10:04:00.000
0
1
0
0
python,smtp
892,264
3
false
0
0
Depends what you mean by "received". It's possible to verify "delivery" of a message to a server but there is no 100% reliable guarantee it actually ended up in a mailbox. smtplib will throw an exception on certain conditions (like the remote end reporting user not found) but just as often the remote end will accept the mail and then either filter it or send a bounce notice at a later time.
1
0
0
buildin an smtp client in python . which can send mail , and also show that mail has been received through any mail service for example gmail !!
How would one build an smtp client in python?
0
0
1
769
892,266
2009-05-21T10:31:00.000
2
0
0
1
python,django,google-app-engine,mail-server
892,427
2
false
1
0
The example code for the remote APi gives you an interactive console from which you can access any of the modules in your application. I see no requirement that they be only datastore operations.
1
0
0
I have a web server with Django, hosted with Apache server. I would like to configure Google App Engine for the email server. My web server should be able to use Google App Engine, when it makes any email send using EmailMessage or sendmail infrastructure of Google Mail API. I learnt that by using Remote API, I can access Google App Engine server from my main web server. However, I could not access the Mail APIs supported by Google App Engine. Is the Remote API strictly for Datastore? If so, can only the DB read from it and no other API calls can?
Send emails from Google App Engine
0.197375
0
0
1,502
893,162
2009-05-21T14:20:00.000
30
0
1
0
python,macos,ide
901,101
22
true
0
0
Have tried many different (Kate, Eclipse, Scite, Vim, Komodo): each one have some glitches, either limited functions, or slow and unresponsive. Final choice after many years: Emacs + ropemacs + flymake. Rope project file open dialog is extremely quick. Rope refactoring and code assist functions are super helpful. Flymake shows syntax mistakes. Emacs is the most configurable editor. I am very happy with this config. Python related part of config is here: public.halogen-dg.com browser/alex-emacs-settings/configs/cfg_python.el
7
135
0
I'm about to start a new job where the coding practices are heavily centered around TDD and refactoring, and whose primary development language is Python. I come from the Java world, and have been a confident user of Eclipse for a good, long time. When not working in Java, I use emacs. I'm looking for an IDE for Python that will give me a lot of the capabilities I've grown used to with Eclipse, not only for refactoring but in terms of code completion, project management, SCM integration (currently CVS, but likely to switch to git one of these days) et al. What IDE should I use?
What's a good IDE for Python on Mac OS X?
1.2
0
0
344,918
893,162
2009-05-21T14:20:00.000
3
0
1
0
python,macos,ide
893,215
22
false
0
0
If you have a budget for your IDE, you should give Wingware Professional a try, see wingware.com .
7
135
0
I'm about to start a new job where the coding practices are heavily centered around TDD and refactoring, and whose primary development language is Python. I come from the Java world, and have been a confident user of Eclipse for a good, long time. When not working in Java, I use emacs. I'm looking for an IDE for Python that will give me a lot of the capabilities I've grown used to with Eclipse, not only for refactoring but in terms of code completion, project management, SCM integration (currently CVS, but likely to switch to git one of these days) et al. What IDE should I use?
What's a good IDE for Python on Mac OS X?
0.027266
0
0
344,918
893,162
2009-05-21T14:20:00.000
1
0
1
0
python,macos,ide
893,233
22
false
0
0
Python support on netbeans is surprisingly good, and comes with most of the features you're looking for.
7
135
0
I'm about to start a new job where the coding practices are heavily centered around TDD and refactoring, and whose primary development language is Python. I come from the Java world, and have been a confident user of Eclipse for a good, long time. When not working in Java, I use emacs. I'm looking for an IDE for Python that will give me a lot of the capabilities I've grown used to with Eclipse, not only for refactoring but in terms of code completion, project management, SCM integration (currently CVS, but likely to switch to git one of these days) et al. What IDE should I use?
What's a good IDE for Python on Mac OS X?
0.009091
0
0
344,918
893,162
2009-05-21T14:20:00.000
1
0
1
0
python,macos,ide
893,407
22
false
0
0
TextMate or Panic's Coda. NetBeans works very well, if you want a full-blown kitchen sink IDE.
7
135
0
I'm about to start a new job where the coding practices are heavily centered around TDD and refactoring, and whose primary development language is Python. I come from the Java world, and have been a confident user of Eclipse for a good, long time. When not working in Java, I use emacs. I'm looking for an IDE for Python that will give me a lot of the capabilities I've grown used to with Eclipse, not only for refactoring but in terms of code completion, project management, SCM integration (currently CVS, but likely to switch to git one of these days) et al. What IDE should I use?
What's a good IDE for Python on Mac OS X?
0.009091
0
0
344,918
893,162
2009-05-21T14:20:00.000
1
0
1
0
python,macos,ide
8,821,307
22
false
0
0
"Which editor/IDE for ...?" is a longstanding way to start a "My dog is too prettier than yours!" slapfest. Nowadays most editors from vim upwards can be used, there are multiple good alternatives, and even IDEs that started as C or Java tools work pretty well with Python and other dynamic languages. That said, having tried a bunch of IDEs (Eclipse, NetBeans, XCode, Komodo, PyCharm, ...), I am a fan of ActiveState's Komodo IDE. I use it on Mac OS X primarily, though I've used it for years on Windows as well. The one license follows you to any platform. Komodo is well-integrated with popular ActiveState builds of the languages themselves (esp. for Windows), works well with the fabulous (and Pythonic) Mercurial change management system (among others), and has good-to-excellent abilities for core tasks like code editing, syntax coloring, code completion, real-time syntax checking, and visual debugging. It is a little weak when it comes to pre-integrated refactoring and code-check tools (e.g. rope, pylint), but it is extensible and has a good facility for integrating external and custom tools. Some of the things I like about Komodo go beyond the write-run-debug loop. ActiveState has long supported the development community (e.g. with free language builds, package repositories, a recipes site, ...), since before dynamic languages were the trend. The base Komodo Edit editor is free and open source, an extension of Mozilla's Firefox technologies. And Komodo is multi-lingual. I never end up doing just Python, just Perl, or just whatever. Komodo works with the core language (Python, Perl, Ruby, PHP, JavaScript) alongside supporting languages (XML, XSLT, SQL, X/HTML, CSS), non-dynamic languages (Java, C, etc.), and helpers (Makefiles, INI and config files, shell scripts, custom little languages, etc.) Others can do that too, but Komodo puts them all in once place, ready to go. It's a Swiss Army Knife for dynamic languages. (This is contra PyCharm, e.g., which is great itself, but I'd need like a half-dozen of JetBrains' individual IDEs to cover all the things I do). Komodo IDE is by no means perfect, and editors/IDEs are the ultimate YMMV choice. But I am regularly delighted to use it, and every year I re-up my support subscription quite happily. Indeed, I just remembered! That's coming up this month. Credit card: Out. I have no commercial connection to ActiveState--just a happy customer.
7
135
0
I'm about to start a new job where the coding practices are heavily centered around TDD and refactoring, and whose primary development language is Python. I come from the Java world, and have been a confident user of Eclipse for a good, long time. When not working in Java, I use emacs. I'm looking for an IDE for Python that will give me a lot of the capabilities I've grown used to with Eclipse, not only for refactoring but in terms of code completion, project management, SCM integration (currently CVS, but likely to switch to git one of these days) et al. What IDE should I use?
What's a good IDE for Python on Mac OS X?
0.009091
0
0
344,918
893,162
2009-05-21T14:20:00.000
0
0
1
0
python,macos,ide
15,312,606
22
false
0
0
I may be a little late for this, but I would recommend Aptana Studio 3.x . Its a based on eclipse and has everything ready-to-go for python. It has very good support for DJango, HTML5 and JQuery. For me its a perfect web-development tool. I do HTML5 and Android development too, this way I do not need to keep switching different IDE's. It my all-in-one solution. Note: you need a good amount of RAM for this to be snazzy !! 4+ GB is awesome !!
7
135
0
I'm about to start a new job where the coding practices are heavily centered around TDD and refactoring, and whose primary development language is Python. I come from the Java world, and have been a confident user of Eclipse for a good, long time. When not working in Java, I use emacs. I'm looking for an IDE for Python that will give me a lot of the capabilities I've grown used to with Eclipse, not only for refactoring but in terms of code completion, project management, SCM integration (currently CVS, but likely to switch to git one of these days) et al. What IDE should I use?
What's a good IDE for Python on Mac OS X?
0
0
0
344,918
893,162
2009-05-21T14:20:00.000
5
0
1
0
python,macos,ide
893,240
22
false
0
0
macvim + pyflakes.vim
7
135
0
I'm about to start a new job where the coding practices are heavily centered around TDD and refactoring, and whose primary development language is Python. I come from the Java world, and have been a confident user of Eclipse for a good, long time. When not working in Java, I use emacs. I'm looking for an IDE for Python that will give me a lot of the capabilities I've grown used to with Eclipse, not only for refactoring but in terms of code completion, project management, SCM integration (currently CVS, but likely to switch to git one of these days) et al. What IDE should I use?
What's a good IDE for Python on Mac OS X?
0.045423
0
0
344,918
894,845
2009-05-21T20:05:00.000
5
0
0
1
python
894,869
2
true
0
0
If you're looking to do recurring scheduled tasks, then the Task Scheduler (Vista) or Scheduled Tasks (XP and, I think, earlier) is the appropriate method on Windows.
1
1
0
I have run a few using batch jobs, but, I am wondering what would be the most appropriate? Maybe using time.strftime?
How can I launch a python script on windows?
1.2
0
0
196
895,163
2009-05-21T21:06:00.000
0
1
0
0
python
895,181
3
false
0
0
Since the RDBMS and the network are the bottlenecks, I see no value in fussing around creating an EXE. On average, most of a web site's transfers are static content (images, .CSS, .JS, etc.) which is best handled by Apache without any Python in the loop. This has huge impact. Reserve Python for the "interesting" and "complex" parts of creating the dynamic HTML. Use a framework.
2
0
0
Assuming the webserver is configured to handle .exe, Can i compile a python CGI file into an exe for speed. What would some pros and cons be to such a desession?
Compiled Python CGI
0
0
0
712
895,163
2009-05-21T21:06:00.000
1
1
0
0
python
895,211
3
false
0
0
You probably don't want to run Python as a CGI if you want it fast. Look at proxies, mod_python, WSGI or FastCGI, as those techinques avoid re-loading python runtime and your app on each request.
2
0
0
Assuming the webserver is configured to handle .exe, Can i compile a python CGI file into an exe for speed. What would some pros and cons be to such a desession?
Compiled Python CGI
0.066568
0
0
712
895,420
2009-05-21T21:58:00.000
0
0
0
0
python
895,439
9
false
1
0
Lookup Django.
1
17
0
I have been doing some work in python, but that was all for stand alone applications. I'm curious to know whether any offshoot of python supports web development? Would some one also suggest a good tutorial or a website from where I can pick up some of the basics of web development using python?
Using python to develop web application
0
0
0
23,044
895,454
2009-05-21T22:05:00.000
2
0
0
0
python,django,dependencies
895,984
4
false
1
0
Normally I advocate for splitting functionality into smaller apps, but a circular dependence between models reflects such a tight integration that you're probably not gaining much from the split and might just consider merging the apps. If that results in an app that feels too large, there may be a way to make the split along a different axis, resulting in a more sane dependency graph.
2
26
0
I am in the middle of developing a Django application, which has quite complicated models (it models a university - courses, modules, lectures, students etc.) I have separated the project into apps, to make the whole thing more organised (apps are courses, schools, people, modules and timeperiods). I am having a problem whereby a model in one app may depend on a model in another - so I must import it. The second app then in turn depends on a model in the first, so there is a cycle and Python throws up an error. How do people deal with this? I understand that apps should be relatively "independent", but in a system like this it doesn't make sense, for example, to use ContentTypes to link students to a module. Does anyone have a similar project that could comment on this case?
Django App Dependency Cycle
0.099668
0
0
7,969
895,454
2009-05-21T22:05:00.000
3
0
0
0
python,django,dependencies
896,090
4
false
1
0
If you're seeing circular model dependency I'm guessing that one of three things is happening: You've defined an inverse relationship to one that's already defined (for instance both course has many lectures and lecture has one course) which is redundant in django You have a model method in the wrong app You're providing functionality in a model method that ought to be in a manager Maybe you could show us what's happening in these models and we can try to figure out why the problem is arising. Circular model dependency is rarely an indication that you need to combine two apps - it's more likely (though not definitely the case) that there's a problem with one of your model definitions. p.s. I am working on a similar django application, but my app structure is probably quite different to your's. I'd be happy to give you a high-level description of it if you're interested.
2
26
0
I am in the middle of developing a Django application, which has quite complicated models (it models a university - courses, modules, lectures, students etc.) I have separated the project into apps, to make the whole thing more organised (apps are courses, schools, people, modules and timeperiods). I am having a problem whereby a model in one app may depend on a model in another - so I must import it. The second app then in turn depends on a model in the first, so there is a cycle and Python throws up an error. How do people deal with this? I understand that apps should be relatively "independent", but in a system like this it doesn't make sense, for example, to use ContentTypes to link students to a module. Does anyone have a similar project that could comment on this case?
Django App Dependency Cycle
0.148885
0
0
7,969
896,112
2009-05-22T02:09:00.000
3
1
1
0
python,python-import
896,128
4
false
0
0
You won't get recursion on imports because Python caches each module and won't reload one it already has.
3
11
0
How do I set up module imports so that each module can access the objects of all the others? I have a medium size Python application with modules files in various subdirectories. I have created modules that append these subdirectories to sys.path and imports a group of modules, using import thisModule as tm. Module objects are referred to with that qualification. I then import that module into the others with from moduleImports import *. The code is sloppy right now and has several of these things, which are often duplicative. First, the application is failing because some module references aren't assigned. This same code does run when unit tested. Second, I'm worried that I'm causing a problem with recursive module imports. Importing moduleImports imports thisModule, which imports moduleImports . . . . What is the right way to do this?
Properly importing modules in Python
0.148885
0
0
16,427
896,112
2009-05-22T02:09:00.000
6
1
1
0
python,python-import
896,137
4
false
0
0
Few pointers You may have already split functionality in various module. If correctly done most of the time you will not fall into circular import problems (e.g. if module a depends on b and b on a you can make a third module c to remove such circular dependency). As last resort, in a import b but in b import a at the point where a is needed e.g. inside function. Once functionality is properly in modules group them in packages under a subdir and add a __init__.py file to it so that you can import the package. Keep such pakages in a folder e.g. lib and then either add to sys.path or set PYTHONPATH env variable from module import * may not be good idea. Instead, import whatever is needed. It may be fully qualified. It doesn't hurt to be verbose. e.g. from pakageA.moduleB import CoolClass.
3
11
0
How do I set up module imports so that each module can access the objects of all the others? I have a medium size Python application with modules files in various subdirectories. I have created modules that append these subdirectories to sys.path and imports a group of modules, using import thisModule as tm. Module objects are referred to with that qualification. I then import that module into the others with from moduleImports import *. The code is sloppy right now and has several of these things, which are often duplicative. First, the application is failing because some module references aren't assigned. This same code does run when unit tested. Second, I'm worried that I'm causing a problem with recursive module imports. Importing moduleImports imports thisModule, which imports moduleImports . . . . What is the right way to do this?
Properly importing modules in Python
1
0
0
16,427
896,112
2009-05-22T02:09:00.000
4
1
1
0
python,python-import
897,001
4
false
0
0
The way to do this is to avoid magic. In other words, if your module requires something from another module, it should import it explicitly. You shouldn't rely on things being imported automatically. As the Zen of Python (import this) has it, explicit is better than implicit.
3
11
0
How do I set up module imports so that each module can access the objects of all the others? I have a medium size Python application with modules files in various subdirectories. I have created modules that append these subdirectories to sys.path and imports a group of modules, using import thisModule as tm. Module objects are referred to with that qualification. I then import that module into the others with from moduleImports import *. The code is sloppy right now and has several of these things, which are often duplicative. First, the application is failing because some module references aren't assigned. This same code does run when unit tested. Second, I'm worried that I'm causing a problem with recursive module imports. Importing moduleImports imports thisModule, which imports moduleImports . . . . What is the right way to do this?
Properly importing modules in Python
0.197375
0
0
16,427
896,421
2009-05-22T05:01:00.000
0
0
0
0
python,django,django-models
3,902,915
5
false
1
0
There are anumber of ways to do this, but here's what I'd do: I'd allow a user to enter an email, username (which must contain at least one letter and no @ symbols) or mobile number. Then, when I validate it: Check for the presence of @. If so, set it as the user's email, hash it appropriately and set it as their username as well. Check to see if it's only numbers, dashes and +. Then, strip the appropriate characters and store it as both mobile number and username (if you're storing the mobile number in another model for SMS purposes or something). If it's not either, just set it as username. I'd also validate the user/phone/email field similarly on login and look in the appropriate place so that if, say, a user signs up with their mobile number and then changes their username (for some other purpose), they can still sign in with their mobile number.
3
14
0
The default Django's User model has some fields, and validation rules, that I don't really need. I want to make registration as simple as possible, i.e. require either email or username, or phone number - all those being unique, hence good as user identifiers. I also don't like default character set for user name that is validated in Django user model. I'd like to allow any character there - why not? I used user-profile django application before to add a profile to user - but this time I'd rather make the class mimimal. But I still want to use the User class, as it gives me an easy way to have parts of site restricted only for users logged in. How do I do it?
How to change default django User model to fit my needs?
0
0
0
12,241
896,421
2009-05-22T05:01:00.000
0
0
0
0
python,django,django-models
898,052
5
false
1
0
You face a bit of a dilemma which really has two solutions if you're committed to avoiding the profile-based customization already pointed out. Change the User model itself, per Daniel's suggestions Write a CustomUser class, subclassing User or copying its functionality. The latter suggestion means that you would have to implement some things that User does automatically manually, but I wonder whether that's as bad as it sounds, especially if you're at the beginning of your project. All you'd have to do is rewrite a middle-ware class and some decorators. Of course, I don't think this buys you anything that 1 won't get you, except that your project shouldn't break if you svn update your django. It may avoid some of the compatibility problems with other apps, but my guess is most problems will exist either way.
3
14
0
The default Django's User model has some fields, and validation rules, that I don't really need. I want to make registration as simple as possible, i.e. require either email or username, or phone number - all those being unique, hence good as user identifiers. I also don't like default character set for user name that is validated in Django user model. I'd like to allow any character there - why not? I used user-profile django application before to add a profile to user - but this time I'd rather make the class mimimal. But I still want to use the User class, as it gives me an easy way to have parts of site restricted only for users logged in. How do I do it?
How to change default django User model to fit my needs?
0
0
0
12,241
896,421
2009-05-22T05:01:00.000
10
0
0
0
python,django,django-models
898,313
5
true
1
0
Rather than modify the User class directly or do subclassing, you can also just repurpose the existing fields. For one site I used the "first_name" field as the "publicly displayed name" of a user and stuff a slugified version of that into the "username" field (for use in URLs). I wrote a custom auth backend to allow people to log in using their "public name" or their email address, and I enforce the uniqueness of both of those at registration time. This plays nicely with other reusable apps and doesn't introduce extra tables or queries. For another site I didn't want usernames at all, just unique emails. In order to satisfy Django's need for a unique username, I just hashed the email address and used that as the username (you have to base64-encode the hash to squeeze it under 30 characters). Custom auth backend to allow login with email. If backwards-compatibility weren't an issue, there are a lot of improvements I'd love to see made to django.contrib.auth and the User model to make them more flexible. But there's quite a lot you can do inside the current constraints with a little creativity.
3
14
0
The default Django's User model has some fields, and validation rules, that I don't really need. I want to make registration as simple as possible, i.e. require either email or username, or phone number - all those being unique, hence good as user identifiers. I also don't like default character set for user name that is validated in Django user model. I'd like to allow any character there - why not? I used user-profile django application before to add a profile to user - but this time I'd rather make the class mimimal. But I still want to use the User class, as it gives me an easy way to have parts of site restricted only for users logged in. How do I do it?
How to change default django User model to fit my needs?
1.2
0
0
12,241
897,020
2009-05-22T09:16:00.000
0
0
1
0
python,database,escaping,sql-injection
2,429,209
9
false
0
0
For a solution to a more generic problem, I have a program where I needed to store any set of characters in a flat file, tab delimited. Obviously, having tabs in the 'set' was causing problems. Instead of output_f.write(str), I used output_f.write(repr(str)), which solved my problem. It is slower to read, as I need to eval() the input when I read it, but overall, it makes the code cleaner because I don't need to check for fringe cases anymore.
2
42
0
I've tried all manner of Python modules and they either escape too much or in the wrong way. What's the best way you've found to escape quotes (", ') in Python?
A good way to escape quotes in a database query string?
0
0
0
110,878
897,020
2009-05-22T09:16:00.000
1
0
1
0
python,database,escaping,sql-injection
9,028,006
9
false
0
0
Triple-double quotes are best for escaping: string = """This will span across 'single quotes', "double quotes", and literal EOLs all in the same string."""
2
42
0
I've tried all manner of Python modules and they either escape too much or in the wrong way. What's the best way you've found to escape quotes (", ') in Python?
A good way to escape quotes in a database query string?
0.022219
0
0
110,878
898,426
2009-05-22T15:19:00.000
3
0
0
0
python,django,e-commerce,shopping-cart
899,393
2
true
1
0
Since you asked: if your needs are that limited, it does sound like a DIY situation to me. I don't see what's so fiddly about it; what complexity there is is all in the pricing formula, and you're planning to supply that either way. Add in Django's built-in session support and you're most of the way there.
1
1
0
I'm about to build a site that has about half a dozen fairly similar products. They're all DVDs so they fit into a very "fixed" database very well. I was going to make a DVD model. Tag them up. All very simple. All very easy. But we need to be able to sell them. The current site outsources the whole purchasing system but that's not going to fly on the new site. We want to integrate everything right up until the payment (for both UX reasons plus we get to customise the process a lot more). The other problem with the outsourced problem is it doesn't account for people that don't need to pay VAT (sales tax) or for the fact you get a discounts if you buy more than one of the same thing, or more than one SKU at the same time. So I've been looking around. Satchmo looks like a whole mini-framework. It has listing options that I just don't need with the quantities of SKUs I'm dealing with. django-cart has been re-hashed as of March but it looks pretty abandoned since then. I'm looking for something that will let me: pass it a model instances, a price and a quantity apply a quantities formula based on the number of unique SKUs and copies in the same title list what's in the cart on every page That's about it (but it's quite fiddly, nevertheless). I can handle the final order processing nonsense. Or am I just being silly? Should I just get on and Do It Myself? If that's your vote, I've never built a cart before so are there any considerations that are not obvious to somebody who has only used shopping carts before?
Django shopping cart/basket solution (or should I DIM)?
1.2
0
0
3,617
898,669
2009-05-22T16:09:00.000
4
0
1
0
python,file,binary
898,691
21
false
0
0
Usually you have to guess. You can look at the extensions as one clue, if the files have them. You can also recognise know binary formats, and ignore those. Otherwise see what proportion of non-printable ASCII bytes you have and take a guess from that. You can also try decoding from UTF-8 and see if that produces sensible output.
1
118
0
How can I tell if a file is binary (non-text) in Python? I am searching through a large set of files in Python, and keep getting matches in binary files. This makes the output look incredibly messy. I know I could use grep -I, but I am doing more with the data than what grep allows for. In the past, I would have just searched for characters greater than 0x7f, but utf8 and the like, make that impossible on modern systems. Ideally, the solution would be fast.
How can I detect if a file is binary (non-text) in Python?
0.038077
0
0
86,979
898,993
2009-05-22T17:25:00.000
0
1
0
0
ironpython
924,632
4
true
0
0
Does your timings include startup time? IronPython 2.6 Beta has radical improvements to startup time and code compilation/execution. Suggest you try that release if you can. Cheers, Davy
1
0
0
It seems that IronPython 2.0.1 executes a script file about 3x slower than IronPython 1.x. I'm not convinced that it isn't something I'm doing so I'm wondering if others have had a similar experience. I have a 200k python script that takes 5 seconds to execute from a file on IP 1.x and nearly 18 seconds in IP 2.0.1!
IronPython 2.0 executes code slowly
1.2
0
0
441
900,929
2009-05-23T05:32:00.000
0
0
1
0
python
900,943
5
false
0
0
In part it is confusing due to the dynamically typed nature of Python, which allows you to operate on a class and an instance in essentially the same way. In other languages, the difference is more concrete in that a class provides a template by which to create an object (instance) and cannot be as directly manipulated as in Python. The benefit of operating on the instance rather than the class is that the class can provide a prototype upon which instances are created.
2
2
0
I have read several documentation already but the definition of "class" and "instance" didnt get really clear for me yet. Looks like that "class" is like a combination of functions or methods that return some result is that correct? And how about the instance? I read that you work with the class you creat trough the instance but wouldnt be easier to just work direct with the class? Sometimes geting the concepts of the language is harder than working with it.
Need help with the class and instance concept in Python
0
0
0
555
900,929
2009-05-23T05:32:00.000
3
0
1
0
python
900,953
5
false
0
0
I am not sure of what level of knowledge you have, so I apologize if this answer is too simplified (then just ignore it). A class is a template for an object. Like a blueprint for a car. The instance of a class is like an actual car. So you have one blueprint, but you can have several different instances of cars. The blueprint and the car are different things. So you make a class that describes what an instance of that class can do and what properties it should have. Then you "build" the instance and get an object that you can work with.
2
2
0
I have read several documentation already but the definition of "class" and "instance" didnt get really clear for me yet. Looks like that "class" is like a combination of functions or methods that return some result is that correct? And how about the instance? I read that you work with the class you creat trough the instance but wouldnt be easier to just work direct with the class? Sometimes geting the concepts of the language is harder than working with it.
Need help with the class and instance concept in Python
0.119427
0
0
555
901,704
2009-05-23T15:13:00.000
3
0
0
0
python,wxpython,wxwidgets
901,806
2
false
0
1
What I did when I encountered such a case was to create a column for IDs and set its width to 0.
1
2
0
I posted this in the mailing list, but the reply I got wasn't too clear, so maybe I'll have better luck here. I currently have a grid with data in it. I would like to know if there is a way to give each generated row an ID, or at least, associate each row with an object. It may make it more clear if I clarify what i'm doing. It is described below. I pull data from an SQL table and display them in the grid. I am allowing for the user to add/delete rows and edit cells. Say the user is viewing a grid that has 3 rows(which is, in turn, a mysql table with 3 rows). If he is on the last row and presses the down arrow key, a new row is created and he can enter data into it and it will be inserted in the database when he presses enter. However, I need a way to find out which rows will use "insert" query and which will use "update" query. So ideally, when the user creates a new row by pressing the down arrow, I would give that row an ID and store it in a list(or, if rows already have IDs, just store it in a list) and when the user finishes entering data in the cells and presses enter, I would check if that row's ID is in the in the list. If it is, i would insert all of that row's cells values into the table, if not, i would update mysql with the values. Hope I made this clear.
Give Wxwidget Grid rows an ID
0.291313
1
0
1,026
902,761
2009-05-24T00:08:00.000
0
0
0
0
python,image,numpy
72,331,083
21
false
0
0
I attach an simple routine to convert a npy to an image. Works 100% and it is a piece of cake! from PIL import Image import matplotlib img = np.load('flair1_slice75.npy') matplotlib.image.imsave("G1_flair_75.jpeg", img)
1
370
1
I have a matrix in the type of a Numpy array. How would I write it to disk it as an image? Any format works (png, jpeg, bmp...). One important constraint is that PIL is not present.
Saving a Numpy array as an image
0
0
0
767,103
903,104
2009-05-24T04:53:00.000
1
0
0
0
javascript,python,cross-domain
903,112
2
false
1
0
Make your app into a Google Gadget, Open Social gadget, or other kind of gadgets -- these are all designed to be embeddable into third-party pages with as little fuss as possible.
1
1
0
I want to create a simple online poll application. I have created a backend in python that handles vote tracking, poll display, results display and admin setup. However, if I wanted a third party to be able to embed the poll in their website, what would be the recommended way of doing so? I would love to be able to provide a little javascript to drop into the third parties web page, but I can't use javascript because it would require a cross-domain access. What approach would provide an easy general solution for third parties?
How to embed a Poll in a Web Page
0.099668
0
1
552
903,818
2009-05-24T14:03:00.000
1
0
1
0
python,class
904,482
6
false
0
0
Not knowing what is you are trying to achieve, i would suggest taking a look at pydispatcher. It allows you to implement the Observer pattern Basically, you register F2 with the dispatcher so that it will be called when a specific 'signal' is emitted. Your F1 'emits a signal' that says "I've been called". The dispatcher then calls F2 (or any number of functions that have registered themselves with that particular signal). Its actually really simpler than it sounds, easy to use, and de-couples your code (F1 does not need to know about F2). (arhh.. I'm a new user and not allowed to include hyperlinks, but pydispatcher is easy to google for)
1
2
0
I have two Python classes, call them "C1" and "C2". Inside C1 is a function named "F1" and inside C2 is a function named "F2". Is there a way to execute F2 each time F1 is run without making a direct call to F2 from within F1? Is there some other mechanism by which to know when a function from inside another class has been called? I welcome any suggestions, but would like to know of some way to achieve this without making an instance of C2 inside C1.
How to tell when a function in another class has been called
0.033321
0
0
343
904,042
2009-05-24T15:56:00.000
2
0
0
0
python,mysql
904,077
2
false
0
0
Use mysql's own ability to log the queries and watch for them.
1
2
0
In diagnosing SQL query problems, it would sometimes be useful to be able to see the query string after parameters are interpolated into it, using MySQLdb's safe interpolation. Is there a way to get that information from either a MySQL exception object or from the connection object itself?
python-mysql : How to get interpolated query string?
0.197375
1
0
817
904,746
2009-05-24T21:56:00.000
27
0
1
0
python,replace
32,574,818
10
false
0
0
If you want to remove everything after the last occurrence of separator in a string I find this works well: <separator>.join(string_to_split.split(<separator>)[:-1]) For example, if string_to_split is a path like root/location/child/too_far.exe and you only want the folder path, you can split by "/".join(string_to_split.split("/")[:-1]) and you'll get root/location/child
2
209
0
I have a string. How do I remove all text after a certain character? (In this case ...) The text after will ... change so I that's why I want to remove all characters after a certain one.
How to remove all characters after a specific character in python?
1
0
0
383,369
904,746
2009-05-24T21:56:00.000
0
0
1
0
python,replace
66,455,567
10
false
0
0
This is in python 3.7 working to me In my case I need to remove after dot in my string variable fees fees = 45.05 split_string = fees.split(".", 1) substring = split_string[0] print(substring)
2
209
0
I have a string. How do I remove all text after a certain character? (In this case ...) The text after will ... change so I that's why I want to remove all characters after a certain one.
How to remove all characters after a specific character in python?
0
0
0
383,369
904,928
2009-05-25T00:11:00.000
720
0
1
0
python,padding,strftime
2,073,189
21
false
0
0
Actually I had the same problem and I realized that, if you add a hyphen between the % and the letter, you can remove the leading zero. For example %Y/%-m/%-d. This only works on Unix (Linux, OS X), not Windows (including Cygwin). On Windows, you would use #, e.g. %Y/%#m/%#d.
5
369
0
When using Python strftime, is there a way to remove the first 0 of the date if it's before the 10th, ie. so 01 is 1? Can't find a %thingy for that? Thanks!
Python strftime - date without leading 0?
1
0
0
188,421
904,928
2009-05-25T00:11:00.000
23
0
1
0
python,padding,strftime
27,125,022
21
false
0
0
quite late to the party but %-d works on my end. datetime.now().strftime('%B %-d, %Y') produces something like "November 5, 2014" cheers :)
5
369
0
When using Python strftime, is there a way to remove the first 0 of the date if it's before the 10th, ie. so 01 is 1? Can't find a %thingy for that? Thanks!
Python strftime - date without leading 0?
1
0
0
188,421
904,928
2009-05-25T00:11:00.000
5
0
1
0
python,padding,strftime
3,285,938
21
false
0
0
For %d you can convert to integer using int() then it'll automatically remove leading 0 and becomes integer. You can then convert back to string using str().
5
369
0
When using Python strftime, is there a way to remove the first 0 of the date if it's before the 10th, ie. so 01 is 1? Can't find a %thingy for that? Thanks!
Python strftime - date without leading 0?
0.047583
0
0
188,421