Title
stringlengths
11
150
A_Id
int64
518
72.5M
Users Score
int64
-42
283
Q_Score
int64
0
1.39k
ViewCount
int64
17
1.71M
Database and SQL
int64
0
1
Tags
stringlengths
6
105
Answer
stringlengths
14
4.78k
GUI and Desktop Applications
int64
0
1
System Administration and DevOps
int64
0
1
Networking and APIs
int64
0
1
Other
int64
0
1
CreationDate
stringlengths
23
23
AnswerCount
int64
1
55
Score
float64
-1
1.2
is_accepted
bool
2 classes
Q_Id
int64
469
42.4M
Python Basics and Environment
int64
0
1
Data Science and Machine Learning
int64
0
1
Web Development
int64
1
1
Available Count
int64
1
15
Question
stringlengths
17
21k
How to monkey patch __init__ module in Python?
4,877,513
0
5
2,709
0
python,django,init,monkeypatching
You can just edit the __init__.py file. There's nothing stopping you and if you do it right nothing bad will happen.
0
0
0
0
2011-02-02T17:08:00.000
2
0
false
4,877,457
1
0
1
2
I know, I know, it's dirty and all. I want to know if it's possible to hijack the __init__ module of a Python module to replace it by your own. I'm asking that because I need to prevent a django lib to start some part of it's init process that make it crashes with our configuration. And yes, it's better to fix the django lib and send back a patch. Yes, I'm in touch with the author about that. But for now, I need a quick fix.
How to monkey patch __init__ module in Python?
4,877,628
4
5
2,709
0
python,django,init,monkeypatching
One way to hijack the import procedure is to simulate the import sometime before it takes place, in another module that is imported before the one you want to monkey-patch. Insert whatever you want into sys.modules with the name of the module as the key, and when the time comes to import the original module, Python will find an entry in sys.modules and will just use that. This may not work if the import is done in some magic way. On the other hand, you can always just copy the original project and patch it to your liking.
0
0
0
0
2011-02-02T17:08:00.000
2
0.379949
false
4,877,457
1
0
1
2
I know, I know, it's dirty and all. I want to know if it's possible to hijack the __init__ module of a Python module to replace it by your own. I'm asking that because I need to prevent a django lib to start some part of it's init process that make it crashes with our configuration. And yes, it's better to fix the django lib and send back a patch. Yes, I'm in touch with the author about that. But for now, I need a quick fix.
Django (w PyCharm) & PYTHON PATH issue
5,418,074
10
5
5,796
0
python,django,pythonpath,pycharm
In pycharm open the settings "cmd" + "," and then to "Project Structure" click on "Sources" to include any modules.
0
0
0
0
2011-02-02T19:03:00.000
2
1
false
4,878,661
1
0
1
2
I have purchased PyCharm and am trying to get things to work however I am encountering this issue.. Once I start a project everything works great... Now if I want a standalone app.. let's say at /users/me/djangoApps I understand I have to add this directory to the python path.. I am trying to do so by creating a file sitecustomize.py at lib/python/2.6/site-packages/ However once I create an app and try to import it I keep getting non excistance errors (yes I have reloaded the python interpreter in pycharm) I reckon I am adding my locations to the python path in the wrong way.. Also I might not have my project location setup correctly (currently /users/me/djangoProjects) Thanks, Novice django'r
Django (w PyCharm) & PYTHON PATH issue
4,878,982
2
5
5,796
0
python,django,pythonpath,pycharm
Don't add that file to your python site-packages, then your django project is gonna be included for all future projects down the road. If you wanna debug, within PyCharm, click the Run tab up top and choose Edit configurations. Choose the project you are working with and make sure you add the directory where your manage.py and settings.pr file are to the "Working Directory". So I assume it might look something like this: Working Directory: /users/me/djangoProjects/{Project Name} If there is something else that you need to add to the Python Path, you can add it it by going to File-Settings-Python Interpreter and then add a new path in the bottom window (but once again this will be used by any project you run in PyCharm But if you are not debugging in PyCharm and just wanna run the app, I find it easier to run it from the command line. I assume you are on Mac by your path, open the Terminal and go to the directory where your project is (same directory as the manage.py file) and type: python manange.py runserver If you want to give it a specific port add it to the end python mange.py runserver 9000 This way you can edit your code in PyCharm and it will get reinterpreted when you save the file. If you are debugging in PyCharm, you need to stop the debugger and run it again to pull in your changes
0
0
0
0
2011-02-02T19:03:00.000
2
0.197375
false
4,878,661
1
0
1
2
I have purchased PyCharm and am trying to get things to work however I am encountering this issue.. Once I start a project everything works great... Now if I want a standalone app.. let's say at /users/me/djangoApps I understand I have to add this directory to the python path.. I am trying to do so by creating a file sitecustomize.py at lib/python/2.6/site-packages/ However once I create an app and try to import it I keep getting non excistance errors (yes I have reloaded the python interpreter in pycharm) I reckon I am adding my locations to the python path in the wrong way.. Also I might not have my project location setup correctly (currently /users/me/djangoProjects) Thanks, Novice django'r
Django: "projects" vs "apps"
4,879,235
70
215
51,295
0
python,django,namespaces,project-organization
Try to answer question: "What does my application do?". If you cannot answer in a single sentence, then maybe you can split it into several apps with cleaner logic. I read this thought somewhere soon after I've started to work with django and I find that I ask this question of myself quite often and it helps me. Your apps don't have to be reusable, they can depend on each other, but they should do one thing.
0
0
0
0
2011-02-02T19:41:00.000
6
1
false
4,879,036
0
0
1
2
I have a fairly complex "product" I'm getting ready to build using Django. I'm going to avoid using the terms "project" and "application" in this context, because I'm not clear on their specific meaning in Django. Projects can have many apps. Apps can be shared among many projects. Fine. I'm not reinventing the blog or forum - I don't see any portion of my product being reusable in any context. Intuitively, I would call this one "application." Do I then do all my work in a single "app" folder? If so... in terms of Django's project.app namespace, my inclination is to use myproduct.myproduct, but of course this isn't allowed (but the application I'm building is my project, and my project is an application!). I'm therefore lead to believe that perhaps I'm supposed to approach Django by building one app per "significant" model, but I don't know where to draw the boundaries in my schema to separate it into apps - I have a lot of models with relatively complex relationships. I'm hoping there's a common solution to this...
Django: "projects" vs "apps"
4,880,013
8
215
51,295
0
python,django,namespaces,project-organization
If so... in terms of Django's project.app namespace, my inclination is to usemyproduct.myproduct, but of course this isn't allowed There is nothing like not allowed. Its your project, no one is restricting you. It is advisable to keep a reasonable name. I don't see any portion of my product being reusable in any context. Intuitively, I would call this one "application." Do I then do all my work in a single "app" folder? In a general django project there are many apps (contrib apps) which are used really in every project. Let us say that your project does only one task and has only a single app (I name it main as thethe project revolves around it and is hardly pluggable). This project too still uses some other apps generally. Now if you say that your project is using just the one app (INSTALLED_APPS='myproduct') so what is use of project defining the project as project.app, I think you should consider some points: There are many other things that the code other than the app in a project handles (base static files, base templates, settings....i.e. provides the base). In the general project.app approach django automatically defines sql schema from models. Your project would be much easier to be built with the conventional approach. You may define some different names for urls, views and other files as you wish, but I don't see the need. You might need to add some applications in future which would be real easy with the conventional django projects which otherwise it may become equally or more difficult and tedious to do. As far as most of the work being done in the app is concerned, I think that is the case with most of django projects.
0
0
0
0
2011-02-02T19:41:00.000
6
1
false
4,879,036
0
0
1
2
I have a fairly complex "product" I'm getting ready to build using Django. I'm going to avoid using the terms "project" and "application" in this context, because I'm not clear on their specific meaning in Django. Projects can have many apps. Apps can be shared among many projects. Fine. I'm not reinventing the blog or forum - I don't see any portion of my product being reusable in any context. Intuitively, I would call this one "application." Do I then do all my work in a single "app" folder? If so... in terms of Django's project.app namespace, my inclination is to use myproduct.myproduct, but of course this isn't allowed (but the application I'm building is my project, and my project is an application!). I'm therefore lead to believe that perhaps I'm supposed to approach Django by building one app per "significant" model, but I don't know where to draw the boundaries in my schema to separate it into apps - I have a lot of models with relatively complex relationships. I'm hoping there's a common solution to this...
django - "manage.py test" fails "table already exists"
4,882,942
15
8
5,175
0
python,django
It might be an error in one of your south migrations. You don't see the problem on the real db because the migration has been executed (with the--fake option maybe) You can try to recreate the db from scracth and see if it works. You can also disable South for unit-tests by adding SOUTH_TESTS_MIGRATE = False in your settings.py. With this option a regular syncdb will be done to create the test database. It will also speed the testing process. I hope it helps
0
0
0
0
2011-02-03T03:26:00.000
4
1.2
true
4,882,377
0
0
1
3
I'm new to the django world. Running some tutorial apps, and when running python manage.py test i'm getting a failure saying that the table already exists. I'm not sure what is going on. I am also running south, and I got no errors when migrating the schema. Any insight is greatly appreciated. TIA Joey
django - "manage.py test" fails "table already exists"
7,374,886
0
8
5,175
0
python,django
and if you are testing with nose: DST_RUN_SOUTH_MIGRATIONS = False
0
0
0
0
2011-02-03T03:26:00.000
4
0
false
4,882,377
0
0
1
3
I'm new to the django world. Running some tutorial apps, and when running python manage.py test i'm getting a failure saying that the table already exists. I'm not sure what is going on. I am also running south, and I got no errors when migrating the schema. Any insight is greatly appreciated. TIA Joey
django - "manage.py test" fails "table already exists"
18,020,458
0
8
5,175
0
python,django
This happens also with Nose when --cover-package=userdata,incorrectname One of package's name is incorrect
0
0
0
0
2011-02-03T03:26:00.000
4
0
false
4,882,377
0
0
1
3
I'm new to the django world. Running some tutorial apps, and when running python manage.py test i'm getting a failure saying that the table already exists. I'm not sure what is going on. I am also running south, and I got no errors when migrating the schema. Any insight is greatly appreciated. TIA Joey
Django + Apache + Windows WSGIDaemonProcess Alternative
8,750,220
1
6
2,617
1
python,django,apache,subprocess,mod-wsgi
I ran into a couple of issues trying to use subprocess under this configuration. Since I am not sure what specifically you had trouble with I can share a couple of things that were not easy for me to solve but in hindsight seem pretty trivial. I was receiving permissions related errors when trying to execute an application. I searched quite a bit but was having a hard time finding Windows specific answers. This one was obvious: I changed the user under which Apache runs to a user with higher permissions. (Note, there are security implications with that so you want to be sure you understand what you are getting in to). Django (depending on your configuration) may store strings as Unicode. I had a command line application I was trying to run with some parameters from my view which was crashing despite having the correct arguments passed in. After a couple hours of frustration I did a type(args) which returned <type 'unicode'> rather than my expected string. A quick conversion resolved that issue.
0
0
0
0
2011-02-03T04:07:00.000
2
0.099668
false
4,882,605
0
0
1
1
After setting up a django site and running on the dev server, I have finally gotten around to figuring out deploying it in a production environment using the recommended mod_wsgi/apache22. I am currently limited to deploying this on a Windows XP machine. My problem is that several django views I have written use the python subprocess module to run programs on the filesystem. I keep getting errors when running the subprocess.Popen I have seen several SO questions that have asked about this, and the accepted answer is to use WSGIDaemonProcess to handle the problem (due to permissions of the apache user, I believe). The only problem with this is that WSGIDaemonProcess is not available for mod_wsgi on Windows. Is there any way that I can use mod_wsgi/apache/windows/subprocess together?
Allow "third party" plugins for my Django app, that don't require config changes?
4,891,078
2
3
827
0
python,django
My suggestion would be to use the Django signal system. Your app should send signals when certain actions occur and then listen to them when the next stage happens. If someone wants to change the behaviour of your app, all they would need to do would be to listen to the relevant signals that your app sends out and modify the data appropriately. This allows for very easy expansion and change of applications without needing to even touch your apps source code. I would make a point though, if someone is using your app it is unlikely to be installed in the project folder so requiring them to place code your apps folder is a bad idea. It will most likely be installed as a module within a virtualenv. Using the signals method I outlined above the person using your app can then just add the handlers in the app in their project that it makes most sense to place the handlers in. Thus they never need to touch your apps source code directory.
0
0
0
0
2011-02-03T19:53:00.000
2
1.2
true
4,890,971
0
0
1
1
I would like to know of a good approach, or programming "pattern" to apply, to allow users of my Django application to drop in "plugins" or "extensions" for my app, without having to add anything to 'installed apps' or edit any configuration. WordPress plugins probably being the best example. New options/settings/menus become available, but I don't have to edit the WordPress config or core files - they just show up in my admin. In Django/Python, what approach or programming "pattern" would you use to begin to develop a type of plugin architecture? I know that WordPress (the example given) is a 'platform' itself, and provides a plugin API, etc. My question is about the patterns involved, and the early stages - preparing for plugins before the application is built, rather than trying to add that functionality later. To be specific, my app accepts "content", and I'd like to provide a way for users to drop in modular "transformers" that provide additional outputs of that content (not just a filter) that may or may not need to accept a few basic settings.
Django: Faking a field in the admin interface?
5,409,234
6
15
11,911
0
python,django,django-admin
It's easy enough to get arbitrary data to show up in change list or make a field show up in the form: list_display arbitrarily takes either actual model properties, or methods defined on the model or the modeladmin, and you can subclass forms.ModelForm to add any field type you'd like to the change form. What's far more difficult/impossible is combining the two, i.e. having an arbitrary piece of data on the change list that you can edit in-place by specifying list_editable. Django seems to only accept a true model property that corresponds to a database field. (even using @property on the method in the model definition is not enough). Has anyone found a way to edit a field not actually present on the model right from the change list page?
0
0
0
0
2011-02-03T20:43:00.000
4
1
false
4,891,506
0
0
1
1
I have a model, Foo. It has several database properties, and several properties that are calculated based on a combination of factors. I would like to present these calculated properties to the user as if they were database properties. (The backing factors would be changed to reflect user input.) Is there a way to do this with the Django admin interface?
How can I access the view function in a Django template tag?
4,891,762
1
0
3,003
0
python,django,django-templates
A view function doesn't have any special status in Django. A template can be rendered anywhere: in a view, inside a templatetag, in a model method, in a utility function... so it's not even clear what you would want to access. But in any case, the general principle is that if you want access to something in a template, you should pass it into the template context.
0
0
0
0
2011-02-03T21:02:00.000
4
0.049958
false
4,891,699
0
0
1
1
What it says on the tin: I want to be able to access either: the view function itself the view name (although this is less useful, I can probably use it to get back to the function) attributes of the view function This needs to be accessed from within a template tag. In short, what I'm trying to do is to mark up view functions with information that can be used by my base template to configure some of the view framing UI; set the title, for example, or populate a generic help object. If someone can suggest a better way to do this, please feel free to provide that answer instead.
Django: String representation of models
4,892,163
23
11
14,854
0
python,django
You can also try __repr__ and __str__ for your logging/debugging purposes. It is possible (at least it should be this way) that your logger/debugger uses repr( object ) to log your objects.
0
0
0
0
2011-02-03T21:40:00.000
2
1
false
4,892,049
0
0
1
1
I would like my models to have two string representations: one that is displayed in the backend logs for debugging purposes, and a cleaner one that is displayed to end users when the model is represented in the HTML. Right now, I'm just overriding __unicode__(). Is there a way to do this?
Which programming language to choose?
4,896,404
0
2
436
0
c++,python,ruby-on-rails
Language should be a means to an end. Pick a project you want to work on, then figure out what you will need to know to get the job done. It's very difficult to get any language-learning to stick without some practical application. And "knowing a language" is not particularly difficult or useful. Knowing how to use most of the important libraries and platforms associated with a language is usually much more time-intensive and useful. As far as picking a project if you can't think of one, maybe try for something on a mobile platform -- Android / iOS / Windows Phone. These are generally useful for learning not only a language, but a complete set of tools to take an idea from concept to published.
0
0
0
1
2011-02-04T09:22:00.000
3
0
false
4,896,361
1
0
1
2
I am a 3rd year CS engineering student, I have done some basic programming in languages like C,C++,Java,Shell,Perl,PHP,Ruby on Rails, Python. But now I wanted to settle for one language, so I thought of finally mastering one scripting language and other compiled one. So I decided to stick with C++ and Python. Can someone suggest me, would these be sufficient for any kind of programming, or for web designing I should stick to ROR?
Which programming language to choose?
4,896,389
0
2
436
0
c++,python,ruby-on-rails
Presently ROR is high in demand for web. As a professional i'll suggest to learn ROR.
0
0
0
1
2011-02-04T09:22:00.000
3
0
false
4,896,361
1
0
1
2
I am a 3rd year CS engineering student, I have done some basic programming in languages like C,C++,Java,Shell,Perl,PHP,Ruby on Rails, Python. But now I wanted to settle for one language, so I thought of finally mastering one scripting language and other compiled one. So I decided to stick with C++ and Python. Can someone suggest me, would these be sufficient for any kind of programming, or for web designing I should stick to ROR?
Creating a python web server to recieve XML HTTP Requests
4,898,364
0
1
1,735
0
python,http,xmlhttprequest
There's absolutely no need to write your own web server. Plenty of options exist, including lightweight ones like nginx. You should use one of those, and either your own custom WSGI code to receive the request, or (better) one of the microframeworks like Flask or Bottle.
0
0
1
0
2011-02-04T12:39:00.000
3
0
false
4,898,066
0
0
1
1
I am currently working on a project to create simple file uploader site that will update the user of the progress of an upload. I've been attempting this in pure python (with CGI) on the server side but to get the progress of the file I obviously need send requests to the server continually. I was looking to use AJAX to do this but I was wondering how hard it would be to, instead of changing to some other framerwork (web.py for instance), just write my own web server for receiving the XML HTTP Requests? My main problem is that sending the request is done from HTML and Javascript so it all seems like magic trickery at the moment. Can anyone advise me as to the best way to go about receiving these requests on the server? EDIT: It seems that a framework would be the way to go. Would web.py be a good route to take?
Converting a dynamic PHP/mySQL website to an archived HTML version?
4,901,187
1
1
1,156
0
php,python,dynamic,static,archive
Using PHP you could write a simple script that would do this: Save current page. Follow links from that page and saving those pages (and for each page repeat from 1). Replace URLs on current page with those leading to saved pages.
0
0
0
1
2011-02-04T17:30:00.000
3
0.066568
false
4,901,039
0
0
1
1
I have a PHP/mySQL site that is no longer going to get any new content added. But I'd like to keep what I do have as an archive and keep it online. Ideally I'd like to convert it to a static site so that it no longer requires a database. If anyone else has gone through this process, are there any tools, scripts, or methodologies that can automate this or at least make this easier? I'd want to be able to do things like make sure that all the links still work (so they'd have to somehow be converted to correctly point to the new static versions), things like that. I have ssh access to the server in question. I'm relatively comfortable with both PHP and Python so tools using those languages would be ideal. Note: there are two basic reasons I'm doing this: cost, as it's much cheaper to host just a collection of static files than a dynamic website (I'm using NearlyFreeSpeech and with the bandwidth I'm using I estimate my costs would go down to well under $1/month). spammers have somehow found my site and keep signing up for accounts (at which point, they're blocked from making comments anyway, but it's still annoying).
RESTful Webservice with embedded IronPython: engine & scope questions
4,903,621
2
1
627
0
c#,web-services,ironpython,openrasta
Per request is the way to go unless all of your code is thread safe. You may get better performance using per application (per session implies you have th notion of "sesions" between you client and server), however the implication there is that all of your code in the "application" is thread safe. So per-request is what you should use unless you know your code to be thread safe. Note also that per application will be faster only if: In order to make things thread safe you've not blocking threads in any way. To a certain extent if the business layer/data layer are extremely "heavy" (take a lot of time to instantiate) then some performance benefit may be gained.
0
0
0
0
2011-02-04T21:05:00.000
2
0.197375
false
4,902,933
0
0
1
2
I have a RESTful C# web service (using Open Rasta) that I want to run IronPython scripts that talk to a CouchDB. One thing I could use some clarification on is: How often do I need a new instance of the python engine and the scope? one each per application? per session? per request? I currently have a static engine at the application level along with a dictionary of compiled scripts; then, per request, I create a new scope and execute the code within that scope... Is that correct? thread safe? and as performant as it could be? EDIT: regarding the bounty Please also answer the question I posed in reply to Jeff: Will a static instance of the engine cause sequential requests from different clients to wait in line to execute? if so I will probably need everything on a per-request basis.
RESTful Webservice with embedded IronPython: engine & scope questions
4,903,789
3
1
627
0
c#,web-services,ironpython,openrasta
A ScriptRuntime/ScriptEngine per application and a Scope per request is exactly how it should be done. Runtimes/Engine are thread-safe and Scopes are not.
0
0
0
0
2011-02-04T21:05:00.000
2
1.2
true
4,902,933
0
0
1
2
I have a RESTful C# web service (using Open Rasta) that I want to run IronPython scripts that talk to a CouchDB. One thing I could use some clarification on is: How often do I need a new instance of the python engine and the scope? one each per application? per session? per request? I currently have a static engine at the application level along with a dictionary of compiled scripts; then, per request, I create a new scope and execute the code within that scope... Is that correct? thread safe? and as performant as it could be? EDIT: regarding the bounty Please also answer the question I posed in reply to Jeff: Will a static instance of the engine cause sequential requests from different clients to wait in line to execute? if so I will probably need everything on a per-request basis.
Pycharm (Python IDE) doesn't auto complete Django modules
40,809,492
2
18
14,576
0
python,django,init,pycharm
I worked out this fix: Go to Preferences > Project:{YourProject} > Python interpreter. I saw that the field for "Project interpreter" said "2.7...", but I was coding with python 3.4 and my project was created with python 3.4. Replace the version of python in the "Project interpreter" field with the Python version by means of which you have created your Django project. Apply changes and restart PyCharm.
0
0
0
0
2011-02-05T10:07:00.000
7
0.057081
false
4,906,246
1
0
1
4
My Python IDE (pycharm) has stopped auto completing my modules (suggestions). I get unresolved references after every django module I try to import so: from django - works, however soon as I add a 'dot' it fails so from django.db import models gives me unresolved errors... The ackward thing is after compiling references DO work. I discovered that all my __init__.py files (everywhere) no longer are marked with python icon and are now notepad icons. Also opening init files in my interpreter gives non-color marked up text (no syntax highlighting). So I think Python doens't recognizes these files. My python interpreter is python 2.6.1 with Django 1.2.4 and my django is installed under: /Lib/python/2.6/site-packages (full directories, not egg) When I unfold sitepackages from external libraries within the IDE I do see colored mark up for all .py files EXCEPT __init__.py files. Hence thats where the issue lives. (I have found posts on google for similar problems but no answers...)
Pycharm (Python IDE) doesn't auto complete Django modules
56,934,298
0
18
14,576
0
python,django,init,pycharm
you should just change your project interpreter if it is using anaconda or etc to standard python interpreter which may be located in this path (C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\python.exe)
0
0
0
0
2011-02-05T10:07:00.000
7
0
false
4,906,246
1
0
1
4
My Python IDE (pycharm) has stopped auto completing my modules (suggestions). I get unresolved references after every django module I try to import so: from django - works, however soon as I add a 'dot' it fails so from django.db import models gives me unresolved errors... The ackward thing is after compiling references DO work. I discovered that all my __init__.py files (everywhere) no longer are marked with python icon and are now notepad icons. Also opening init files in my interpreter gives non-color marked up text (no syntax highlighting). So I think Python doens't recognizes these files. My python interpreter is python 2.6.1 with Django 1.2.4 and my django is installed under: /Lib/python/2.6/site-packages (full directories, not egg) When I unfold sitepackages from external libraries within the IDE I do see colored mark up for all .py files EXCEPT __init__.py files. Hence thats where the issue lives. (I have found posts on google for similar problems but no answers...)
Pycharm (Python IDE) doesn't auto complete Django modules
24,810,990
2
18
14,576
0
python,django,init,pycharm
Trivial solution that worked for me: start a new django project using pycharm project options. Try auto-completing using a django import module. If it works, switch back to your original project and auto-complete should be working fine. I still don't understand why this works.
0
0
0
0
2011-02-05T10:07:00.000
7
0.057081
false
4,906,246
1
0
1
4
My Python IDE (pycharm) has stopped auto completing my modules (suggestions). I get unresolved references after every django module I try to import so: from django - works, however soon as I add a 'dot' it fails so from django.db import models gives me unresolved errors... The ackward thing is after compiling references DO work. I discovered that all my __init__.py files (everywhere) no longer are marked with python icon and are now notepad icons. Also opening init files in my interpreter gives non-color marked up text (no syntax highlighting). So I think Python doens't recognizes these files. My python interpreter is python 2.6.1 with Django 1.2.4 and my django is installed under: /Lib/python/2.6/site-packages (full directories, not egg) When I unfold sitepackages from external libraries within the IDE I do see colored mark up for all .py files EXCEPT __init__.py files. Hence thats where the issue lives. (I have found posts on google for similar problems but no answers...)
Pycharm (Python IDE) doesn't auto complete Django modules
7,276,265
21
18
14,576
0
python,django,init,pycharm
I had exactly the same issue and couldn't find a definitive answer. Just invalidating caches didn't work for me. The problem lies in the fact that, at some point, __init__.py files got registered as text files and messed up the indexing. I worked out this fix: Preferences > File Types > Text Files. Remove __init__.py from the list of registered patterns. Apply. Wait for your indexes to re-build. (If it's still not working) File > Invalidate caches & restart.
0
0
0
0
2011-02-05T10:07:00.000
7
1
false
4,906,246
1
0
1
4
My Python IDE (pycharm) has stopped auto completing my modules (suggestions). I get unresolved references after every django module I try to import so: from django - works, however soon as I add a 'dot' it fails so from django.db import models gives me unresolved errors... The ackward thing is after compiling references DO work. I discovered that all my __init__.py files (everywhere) no longer are marked with python icon and are now notepad icons. Also opening init files in my interpreter gives non-color marked up text (no syntax highlighting). So I think Python doens't recognizes these files. My python interpreter is python 2.6.1 with Django 1.2.4 and my django is installed under: /Lib/python/2.6/site-packages (full directories, not egg) When I unfold sitepackages from external libraries within the IDE I do see colored mark up for all .py files EXCEPT __init__.py files. Hence thats where the issue lives. (I have found posts on google for similar problems but no answers...)
Python web frameworks vs Java web frameworks (how is web development in Python done?)
4,909,342
2
6
5,940
0
java,python,templates,web-frameworks
It may sound strange, but there's no need to know "how web development is performed in Python" to start doing it. In fact, working with language/framework/etc is a single most reliable way to get understanding of it. You won't gain a lot from one-page summaries. Also, comparing it with Java isn't likely to help. There's no point in doing "Java-style development in Python". If you want to benefit, you'll need to clear your mind and do everything "Python-way". As to what Python framework to choose, Django seems like like a good starting point. It's very popular, which means you won't be left without tutorials/documentation/help. PS Short version: just do it.
0
0
0
1
2011-02-05T19:57:00.000
4
0.099668
false
4,909,306
0
0
1
2
I am thinking in starting a personal pet web project to experiment with different things and extend my knowledge. I use Java a lot at work (for web applications :D) and was thinking in making my own in Python since I kinda like this language but never passed the simple scripts stages. I want to step up a gear regarding Python (using 2.6.5) and don't know what to expect or what framework to choose from: Django, Pylons, web2py etc. I also don't know how much these frameworks will offer me and how much will I have to write from scratch. I could use a comparison with Java if somebody can provide me with. I'm thinking at filter functionalities such as sitemesh, custom tags like JSTL; In Python, can I write clean pages of HTML with tags in them or write a lot of print statements (something like servlets did in Java etc? I don't know exactly how to phrase this question. I actually need a presentation of how web development is performed in Python, at what level, and what the web frameworks bring to the table. Can you share from your experience? TIA!
Python web frameworks vs Java web frameworks (how is web development in Python done?)
6,586,407
3
6
5,940
0
java,python,templates,web-frameworks
hi try bottle python framework (bottle.paws.de / bottlepy.org) its really nice to use blistering fast and gets out of your way + the best thing about it is that its one single file to import, i recently migrated from PHP and i have to tell you am so ... loving it!
0
0
0
1
2011-02-05T19:57:00.000
4
0.148885
false
4,909,306
0
0
1
2
I am thinking in starting a personal pet web project to experiment with different things and extend my knowledge. I use Java a lot at work (for web applications :D) and was thinking in making my own in Python since I kinda like this language but never passed the simple scripts stages. I want to step up a gear regarding Python (using 2.6.5) and don't know what to expect or what framework to choose from: Django, Pylons, web2py etc. I also don't know how much these frameworks will offer me and how much will I have to write from scratch. I could use a comparison with Java if somebody can provide me with. I'm thinking at filter functionalities such as sitemesh, custom tags like JSTL; In Python, can I write clean pages of HTML with tags in them or write a lot of print statements (something like servlets did in Java etc? I don't know exactly how to phrase this question. I actually need a presentation of how web development is performed in Python, at what level, and what the web frameworks bring to the table. Can you share from your experience? TIA!
Problem with mod_wsgi
4,922,237
2
0
257
0
python,mod-wsgi
If using embedded mode of mod_wsgi you use WSGIPythonPath directive. If you are using daemon mode, you use the python-path option to the appropriate WSGIDaemonProcess directive. Ensure you are not using mod_wsgi 1.X and not using mod_python in same Apache.
0
0
0
0
2011-02-06T01:14:00.000
1
0.379949
false
4,910,875
0
0
1
1
I installed my django project on Apache web server using mod_wsgi. I used a WSGIScriptAlias directive inside VirtualHost, pointing to a wsgi_handler.py file in my project. It worked fine. Nevertheless, I had to write inside the wsgi_handler.py something like: sys.append(absolute_file_path) in order to include some python libraries. Is it possible to do this in a server config file for all wsgi aliases? I have tried setting WSGIPythonPath inside mod_wsgi.conf to no success. Any help appreciated.
ImproperlyConfigured: Error importing middleware django.middleware.common: "No module named _md5"
5,279,438
0
2
6,980
0
python,django,apache,ubuntu,mod-wsgi
So to wrap this up, we ended up re-installing the OS. I know this is a cop out but it fixed the problem for us. Thanks for everyone's help!
0
0
0
0
2011-02-06T03:11:00.000
3
1.2
true
4,911,289
0
0
1
2
I am running Apache2 on Ubuntu 9 with python 2.6.2 installed. I get the following error when I try to access a page on my django application: File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 42, in load_middleware raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))ImproperlyConfigured: Error importing middleware django.middleware.common: "No module named _md5" Here is my wsgi file: import os, sys sys.path.append('/etc/apache2/sites-available/') os.environ['DJANGO_SETTINGS_MODULE'] = 'dynamicuddi.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() From what I've read I think it's a python path problem but I haven't seen an actual solution to this that has worked. Any ideas? Thanks in advance.
ImproperlyConfigured: Error importing middleware django.middleware.common: "No module named _md5"
4,911,387
1
2
6,980
0
python,django,apache,ubuntu,mod-wsgi
Try to append to python path you project directory and parent one sys.path.append('path_to_dynamicuddi_project') sys.path.append('path_to_dynamicuddi_parent_dir')
0
0
0
0
2011-02-06T03:11:00.000
3
0.066568
false
4,911,289
0
0
1
2
I am running Apache2 on Ubuntu 9 with python 2.6.2 installed. I get the following error when I try to access a page on my django application: File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 42, in load_middleware raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))ImproperlyConfigured: Error importing middleware django.middleware.common: "No module named _md5" Here is my wsgi file: import os, sys sys.path.append('/etc/apache2/sites-available/') os.environ['DJANGO_SETTINGS_MODULE'] = 'dynamicuddi.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() From what I've read I think it's a python path problem but I haven't seen an actual solution to this that has worked. Any ideas? Thanks in advance.
Extract 2nd level domain from domain? - Python
4,916,929
3
7
3,869
0
javascript,jquery,python,html,django
Problem in mix of extractions 1st and 2nd level. Trivial solution... Build list of possible site suffixes, ordered from narrow to common case. "co.uk", "uk", "co.jp", "jp", "com" And check, Can suffix be matched at end of domain. if matched, next part is site.
0
0
0
0
2011-02-06T23:20:00.000
6
0.099668
false
4,916,890
1
0
1
2
I have a list of domains e.g. site.co.uk site.com site.me.uk site.jpn.com site.org.uk site.it also the domain names can contain 3rd and 4th level domains e.g. test.example.site.org.uk test2.site.com I need to try and extract the 2nd level domain, in all these cases being site Any ideas? :)
Extract 2nd level domain from domain? - Python
4,916,933
2
7
3,869
0
javascript,jquery,python,html,django
The only possible way would be via a list with all the top level domains (here like .com or co.uk) possible. Then you would scan through this list and check out. I don't see any other way, at least without accessing the internet at runtime.
0
0
0
0
2011-02-06T23:20:00.000
6
0.066568
false
4,916,890
1
0
1
2
I have a list of domains e.g. site.co.uk site.com site.me.uk site.jpn.com site.org.uk site.it also the domain names can contain 3rd and 4th level domains e.g. test.example.site.org.uk test2.site.com I need to try and extract the 2nd level domain, in all these cases being site Any ideas? :)
Starting a long running process on a server from a WSGI application
4,919,128
2
3
919
0
python,wsgi
Isolate the process as a separate daemon, and use MQ or some other IPC to hand it jobs. Have it update a value in a database as it progresses, and read that value in a web page.
0
0
0
0
2011-02-07T07:15:00.000
2
0.197375
false
4,918,867
0
0
1
2
I need to start a long running process (30 min) via http and get status as it's running. The "process" is basically a Python script that updates a database. I have the following constraints: Only one instance of the process can run at a time. The WSGI application is running in several interpreters, so I can't just make a global variable isRunning to keep track of it. I need a web page to track the process (status/progress) No Django, just pure WSGI. Anyone have any experiences doing the same thing?
Starting a long running process on a server from a WSGI application
4,922,650
1
3
919
0
python,wsgi
Look at using Celery (http://celeryproject.org/) and run the task outside of the Python web application processes.
0
0
0
0
2011-02-07T07:15:00.000
2
0.099668
false
4,918,867
0
0
1
2
I need to start a long running process (30 min) via http and get status as it's running. The "process" is basically a Python script that updates a database. I have the following constraints: Only one instance of the process can run at a time. The WSGI application is running in several interpreters, so I can't just make a global variable isRunning to keep track of it. I need a web page to track the process (status/progress) No Django, just pure WSGI. Anyone have any experiences doing the same thing?
How do I do logging in a WSGI application across several processes?
4,922,546
1
3
1,543
0
python,logging,wsgi
Direct logging output to sys.stderr. Doing that will see anything logged get routed into the internal Apache logging routines and into the Apache error logs. The way Apache does this works when done from multiple process at the same time.
0
0
0
0
2011-02-07T08:03:00.000
3
0.066568
false
4,919,133
0
0
1
1
I have a simple webservice written in Python WSGI, it's running in Apache and modwsgi using the WSGIDaemonProcess processes=4 directive. How do I add logging? Obviously I can't log to the same file without some sort of mutex, but I don't want performance degraded. The logging can't block. As far as I know the standard logging module blocks on every log call. I was thinking of doing some sort of socket logging, is this viable? Would it require a "server" process to receive logging? What happens if the server isn't on?
Actionscript Three Asymmetric Encryption
4,999,135
0
0
191
0
python,actionscript,cryptography,token,encryption-asymmetric
After doing some research I have decided to code the part of rsa I need from scratch. I found some python code that will generate raw integer keys of any length and looked up how the rsa algorithm works. T^P = X (mod R) to encrypt X^Q = T (mod R) to decrypt Where T is the starting data, X is the ending data, P is the public half of the key, Q is the private half of the key, and R is the shared part of the key (all integers). Data will have a nonice whenever possible to prevent replay attacks and the message as a whole will be converted to a long integer to prevent traditional bit by bit cryptanalysis.
0
0
0
1
2011-02-08T08:53:00.000
3
1.2
true
4,931,126
0
0
1
3
I cant seem to find a reliable asymmetric encryption solution to secure data between a python based server application and a client over an open data channel. I need some way for my client to prevent a man in the middle attack over an open data channel, my current exchange has me sending my clients a token they use to verify they are talking to my server application by checking the token is valid with a php script on my site. This is far from ideal and could easily be compromised by waiting to be sent the token and passing it off to another user. I have tried as3crypto's rsa encryption but it is an old implementation that is not supported by many libraries as well as having a known vulnerability. I would really like a solution that lets me hard code public/private keys into both the client and server to prevent something like this from happening.
Actionscript Three Asymmetric Encryption
4,947,928
0
0
191
0
python,actionscript,cryptography,token,encryption-asymmetric
Hardcoding they public keys won't help you, if someone really plans an attack, because the SWF itself is transfered over an unsafe channel, thus the keys can be exchanged just as if they were transmitted individually. There is basically nothing you can do to prevent man in the middle attacks, you can only make them harder. I think HTTPS is about the best you can get and it's also a fairly easy solution.
0
0
0
1
2011-02-08T08:53:00.000
3
0
false
4,931,126
0
0
1
3
I cant seem to find a reliable asymmetric encryption solution to secure data between a python based server application and a client over an open data channel. I need some way for my client to prevent a man in the middle attack over an open data channel, my current exchange has me sending my clients a token they use to verify they are talking to my server application by checking the token is valid with a php script on my site. This is far from ideal and could easily be compromised by waiting to be sent the token and passing it off to another user. I have tried as3crypto's rsa encryption but it is an old implementation that is not supported by many libraries as well as having a known vulnerability. I would really like a solution that lets me hard code public/private keys into both the client and server to prevent something like this from happening.
Actionscript Three Asymmetric Encryption
4,947,858
0
0
191
0
python,actionscript,cryptography,token,encryption-asymmetric
Since decompiling swf content is not a major problem for experienced hackers, I would strongly advise against hardcoding keys. Have you thought about using SSL at all?
0
0
0
1
2011-02-08T08:53:00.000
3
0
false
4,931,126
0
0
1
3
I cant seem to find a reliable asymmetric encryption solution to secure data between a python based server application and a client over an open data channel. I need some way for my client to prevent a man in the middle attack over an open data channel, my current exchange has me sending my clients a token they use to verify they are talking to my server application by checking the token is valid with a php script on my site. This is far from ideal and could easily be compromised by waiting to be sent the token and passing it off to another user. I have tried as3crypto's rsa encryption but it is an old implementation that is not supported by many libraries as well as having a known vulnerability. I would really like a solution that lets me hard code public/private keys into both the client and server to prevent something like this from happening.
Loading a pickled list just once - Django\Python
4,933,720
2
3
1,933
0
python,django,django-views,pickle
I'd write a python module - a singleton class with an init method that reads the pickled data into a python object, and then whatever 'get' methods you need to get the info out. Then in your settings.py you just call the initialisation method. Anything that needs to get info from it just imports the module and uses the get methods.
0
0
0
0
2011-02-08T12:46:00.000
3
0.132549
false
4,933,190
1
0
1
1
I have a pickle file that contains a list of compiled regexes and other data. It takes about 1-1.5 seconds to load. What could a good way of using this list into my views, but have pickle work on the file just once? Edit: would importing into settings.py be considered ok? Any ideas?
Testing Apache/mod_jk/Tomcat configuration upgrade
4,949,650
0
0
361
0
python,apache,tomcat,web-scraping,mod-jk
In order to accomplish what I wanted to do, I just went back to basics. Mechanize is somewhat bulky, and there was a lot of bloat involved in the main functionality tests I had before. So I started with a clean slate and just used cookielib.CookieJar and urllib2 to build a linear test and then run them in a while 1 loop. This provided enough strain on the Apache system to see how it would react in the new environment, and for the record, it did VERY well.
0
0
0
0
2011-02-08T17:56:00.000
2
1.2
true
4,936,524
1
0
1
1
We have begun upgrading hardware and software to a 64-bit architecture using Apache with mod_jk and four Tomcat servers (the new hardware). We need to be able to test this equipment with a large number of simultaneous connections while still actually doing things in the app (logging in, etc.) I currently am using Python with the Mechanize library to do this, but it's just not cutting it. Threading is not "real" in Python, and multiprocessing makes the local box work harder than the machines we are trying to test since it has to load so much into memory for Mechanize. The bottom line is that I need something that will really hammer this thing's connections and hold a session to make sure that the sticky sessions are working in mod_jk. I need to be able to code it quickly, it needs to be lightweight, and being able to do true multithreading would be a perk. Other than that, I am open-minded. Any input will be greatly appreciated. Thanks.
TDD django models
4,937,874
6
2
360
0
python,django,tdd
Shouldn't tests test functionality rather than implementation? In other words, test that the field can store an integer, not that it is an IntegerField. Then if that gets changed to a BooleanField your test fails (assuming no coercion), but if it gets changed to a FloatField the test still passes, because it can still store an integer.
0
0
0
0
2011-02-08T20:03:00.000
3
1
false
4,937,762
0
0
1
3
If you're trying to do Test Driven Development, is it sane to write tests that check the column type of your models as you write your models? Like before you write your model, you write a test and say I want an ID field that is an integer field.
TDD django models
4,937,780
7
2
360
0
python,django,tdd
I think it's a bit overkill to test the underlying framework within your app testing, in general. Unless you have a suspicion that it isn't well-tested and/or it is something that may change a lot (say you live by developing against trunk), it should be a reasonable assumption that your framework will operate as advertised/documented.
0
0
0
0
2011-02-08T20:03:00.000
3
1.2
true
4,937,762
0
0
1
3
If you're trying to do Test Driven Development, is it sane to write tests that check the column type of your models as you write your models? Like before you write your model, you write a test and say I want an ID field that is an integer field.
TDD django models
4,937,956
3
2
360
0
python,django,tdd
If you don't want to drive yourself crazy, you should focus on tests that will really help you. Testing that the id column is an integer isn't testing your code, it's testing Django. Even testing that "subject" is a string field isn't helping you much. Test that the models can do what they have to do.
0
0
0
0
2011-02-08T20:03:00.000
3
0.197375
false
4,937,762
0
0
1
3
If you're trying to do Test Driven Development, is it sane to write tests that check the column type of your models as you write your models? Like before you write your model, you write a test and say I want an ID field that is an integer field.
Django Admin - change header 'Django administration' text
61,366,946
7
254
156,772
0
python,django,django-admin
Just go to admin.py file and add this line in the file : admin.site.site_header = "My Administration"
0
0
0
0
2011-02-08T21:10:00.000
21
1
false
4,938,491
0
0
1
3
How does one change the 'Django administration' text in the django admin header? It doesn't seem to be covered in the "Customizing the admin" documentation.
Django Admin - change header 'Django administration' text
62,750,378
5
254
156,772
0
python,django,django-admin
You can use these following lines in your main urls.py you can add the text in the quotes to be displayed To replace the text Django admin use admin.site.site_header = "" To replace the text Site Administration use admin.site.site_title = "" To replace the site name you can use admin.site.index_title = "" To replace the url of the view site button you can use admin.site.site_url = ""
0
0
0
0
2011-02-08T21:10:00.000
21
0.047583
false
4,938,491
0
0
1
3
How does one change the 'Django administration' text in the django admin header? It doesn't seem to be covered in the "Customizing the admin" documentation.
Django Admin - change header 'Django administration' text
4,938,653
3
254
156,772
0
python,django,django-admin
You just override the admin/base_site.html template (copy the template from django.contrib.admin.templates and put in your own admin template dir) and replace the branding block.
0
0
0
0
2011-02-08T21:10:00.000
21
0.028564
false
4,938,491
0
0
1
3
How does one change the 'Django administration' text in the django admin header? It doesn't seem to be covered in the "Customizing the admin" documentation.
django how to use AUTH_PROFILE_MODULE with multiple profiles?
4,966,022
0
2
1,474
0
python,django,django-models
It may be more hassle to try to use multiple profiles with the simplistic configuration of UserProfile. I would suggest using UserProfile with generic foreign key, or completely ditch UserProfile and create separate models with a User foreign key. If you are going to have a lot of data attached to these extra user profiles, I would keep them in models separate from UserProfile. My personal opinion about UserProfile is that it can quickly become the dumping ground for user data that doesn't have a nice home. Don't think that you have to use UserProfile just because your data sounds like it is profile information. I don't think UserProfile was ever intended to solve all the problems. I see it as a way to make up for the fact that the code for the User model is under django code and we don't generally mess with it to add user data.
0
0
0
0
2011-02-09T03:50:00.000
2
0
false
4,941,125
0
0
1
1
Assuming I have different profiles for different user types - staff, teacher,students: How do I specify AUTH_PROFILE_MODULE in order to get back the appropriate profile with get_profile?
Which django apps are directly usable or easily adaptable for django-nonrel?
5,656,577
0
2
198
0
python,django,google-app-engine,django-nonrel
I have used 'contenttypes, auth and sessions' from 'django.contrib' without any modification, the app code wont cause any problems. However any query using JOINs result in query errors, so you need to write your queries with this limitation in mind. Did you have a particular app in mind?
0
0
0
0
2011-02-09T21:53:00.000
3
0
false
4,950,962
0
0
1
1
Is there a list of django apps that can be used unaltered in django-nonrel or a list of django apps that can be easily adapted to be used in django-nonrel?
Which version of Python should I use for web development?
4,957,642
1
6
893
0
python,version
Go with Python 2.7, especially if you're looking to do Django work or any other web development. Python 3 isn't supported with Django, and most libraries work with the > 2.5 versions of Python.
0
0
0
0
2011-02-10T13:18:00.000
6
0.033321
false
4,957,545
0
0
1
3
I've finally decided to start working in Python but there seems to be so many versions out there. I'm mainly interested in web development in Python, so which version should I choose? I don't know what versions the web frameworks usually support (Django, Pylons and so on) but maybe you guys know? Also, I'd like to know the key differences between the versions. Thanks.
Which version of Python should I use for web development?
4,958,047
0
6
893
0
python,version
You use the version supported by the web framework of your choice. That will typically today be Python 2.6 or 2.7.
0
0
0
0
2011-02-10T13:18:00.000
6
0
false
4,957,545
0
0
1
3
I've finally decided to start working in Python but there seems to be so many versions out there. I'm mainly interested in web development in Python, so which version should I choose? I don't know what versions the web frameworks usually support (Django, Pylons and so on) but maybe you guys know? Also, I'd like to know the key differences between the versions. Thanks.
Which version of Python should I use for web development?
4,957,702
0
6
893
0
python,version
If you want to use shared hosters than you should use Version 2.5, because the most of them only have 2.5 (at least in my country). And if you want to use a newer version of Python, 2.7 is compatible to 2.5.
0
0
0
0
2011-02-10T13:18:00.000
6
0
false
4,957,545
0
0
1
3
I've finally decided to start working in Python but there seems to be so many versions out there. I'm mainly interested in web development in Python, so which version should I choose? I don't know what versions the web frameworks usually support (Django, Pylons and so on) but maybe you guys know? Also, I'd like to know the key differences between the versions. Thanks.
In django, can you load a django app into the python interpreter like in rails?
4,961,970
24
4
3,150
0
python,django
you mean python manage.py shell ?
0
0
0
0
2011-02-10T19:56:00.000
3
1.2
true
4,961,951
0
0
1
2
In django, can you load a django app into the python interpreter like in rails? i.e. does django have: irb ?
In django, can you load a django app into the python interpreter like in rails?
4,961,987
2
4
3,150
0
python,django
yes, it can be via python manage.py shell, it's also useful to look into the django-extensions plugin for extra functionality such as shell_plus which provides all of the database interactions for the shell environment as welll.
0
0
0
0
2011-02-10T19:56:00.000
3
0.132549
false
4,961,951
0
0
1
2
In django, can you load a django app into the python interpreter like in rails? i.e. does django have: irb ?
In python, is it easy to call a function multiple times using threads?
4,962,704
0
2
1,238
0
python,multithreading
You can do this using any of: the thread module (if your task is a function) the threading module (if you want to write your task as a subclass of threading.Thread) the multiprocessing module (which uses a similar interface to threading) All of these are available in the Python standard library (2.6 and later), and you can get the multiprocessing module for earlier versions as well (it just wasn't packaged with Python yet).
0
0
0
0
2011-02-10T20:02:00.000
2
0
false
4,962,022
1
0
1
1
Say I have a simple function, it connects to a database (or a queue), gets a url that hasn't been visited, and then fetches the HTML at the given URL. Now this process is serial, i.e. it will only fetch the html from a given url one at a time, how can I make this faster by doing this in a group of threads?
BeautifulSoup and lxml.html - what to prefer?
4,967,121
44
40
44,819
0
python,beautifulsoup,lxml
The simple answer, imo, is that if you trust your source to be well-formed, go with the lxml solution. Otherwise, BeautifulSoup all the way. Edit: This answer is three years old now; it's worth noting, as Jonathan Vanasco does in the comments, that BeautifulSoup4 now supports using lxml as the internal parser, so you can use the advanced features and interface of BeautifulSoup without most of the performance hit, if you wish (although I still reach straight for lxml myself -- perhaps it's just force of habit :)).
0
0
1
0
2011-02-11T08:49:00.000
4
1.2
true
4,967,103
0
0
1
2
I am working on a project that will involve parsing HTML. After searching around, I found two probable options: BeautifulSoup and lxml.html Is there any reason to prefer one over the other? I have used lxml for XML some time back and I feel I will be more comfortable with it, however BeautifulSoup seems to be much common. I know I should use the one that works for me, but I was looking for personal experiences with both.
BeautifulSoup and lxml.html - what to prefer?
4,968,489
0
40
44,819
0
python,beautifulsoup,lxml
lxml's great. But parsing your input as html is useful only if the dom structure actually helps you find what you're looking for. Can you use ordinary string functions or regexes? For a lot of html parsing tasks, treating your input as a string rather than an html document is, counterintuitively, way easier.
0
0
1
0
2011-02-11T08:49:00.000
4
0
false
4,967,103
0
0
1
2
I am working on a project that will involve parsing HTML. After searching around, I found two probable options: BeautifulSoup and lxml.html Is there any reason to prefer one over the other? I have used lxml for XML some time back and I feel I will be more comfortable with it, however BeautifulSoup seems to be much common. I know I should use the one that works for me, but I was looking for personal experiences with both.
What could cause a Django error when debug=False that isn't there when debug=True
11,999,402
1
16
9,930
0
python,django,apache,debugging,importerror
This can also happen if you do not have both a 500.html and 404.html template present. Just the 500 isn't good enough, even for URIs that won't produce a 404!
0
0
0
0
2011-02-11T15:01:00.000
4
0.049958
false
4,970,489
0
0
1
2
Using the development server, it works with debug=True or False. In production, everything works if debug=True, but if debug=False, I get a 500 error and the apache logs end with an import error: "ImportError: cannot import name Project". Nothing in the import does anything conditional on debug - the only code that does is whether the development server should serve static files or not (in production, apache should handle this - and this is tested separately and works fine).
What could cause a Django error when debug=False that isn't there when debug=True
4,975,210
7
16
9,930
0
python,django,apache,debugging,importerror
This happens if you have a circular import in one of your files. Check and see if you are importing something from Project and then importing something in Project from the original file that originally imported Project. I ran into this same problem recently, and rearranging some of my imports helped fix the problem.
0
0
0
0
2011-02-11T15:01:00.000
4
1.2
true
4,970,489
0
0
1
2
Using the development server, it works with debug=True or False. In production, everything works if debug=True, but if debug=False, I get a 500 error and the apache logs end with an import error: "ImportError: cannot import name Project". Nothing in the import does anything conditional on debug - the only code that does is whether the development server should serve static files or not (in production, apache should handle this - and this is tested separately and works fine).
Materialize data from cache table to production table [PostgreSQL]
4,973,738
1
0
611
1
python,postgresql,triggers,materialized-views
The "best" solution according to the criteria you've laid out so far would just be to insert into the production table. ...unless there's actually something extremely relevant you're not telling us
0
0
0
0
2011-02-11T19:46:00.000
1
0.197375
false
4,973,316
0
0
1
1
I am trying to find the best solution (perfomance/easy code) for the following situation: Considering a database system with two tables, A (production table) and A'(cache table): Future rows are added first into A' table in order to not disturb the production one. When a timer says go (at midnight, for example) rows from A' are incorporated to A. Dealing with duplicates, inexistent rows, etc have to be considerated. I've been reading some about Materialized Views, Triggers, etc. The problem is that I should not introduce so much noise in the production table because is the reference table for a server (a PowerDNS server in fact). So, what do you guys make of it? Should I better use triggers, MV, or programatically outside of the database?? (I'm using python, BTW) Thanks in advance for helping me.
Python / Django - Organizing Stylesheets and Scripts
4,974,601
5
1
1,218
0
python,django,django-templates,stylesheet
Look at the django.contrib.admin application. Parallel the way the admin site works. Create a media directory. Create media/img, media/jss, media/css, media/whatever directories In each of these, you'll have your app's specific stuff. media/img/app1, media/jss/app1 so that each of your Django apps can have specific media without conflict or problems. Be sure that your settings have the MEDIA_ROOT set. You'll want to read about this in the Django docs. You'll also have to set your MEDIA_URL for deployment. And you'll have to figure out how to make your webserver (i.e., Apache) serve this media. Django should not be serving static files like .js libraries or .css files or any images. It's a waste of time. Apache can serve this just fine. For testing purposes, however, you can enable a simple file server capability in your Django site. Finally. And most importantly. Be sure that your page template actually references the various files you want to include on your page {{MEDIA_URL}}css/site.css, and {{MEDIA_URL}}js/app1/something.js.
0
0
0
0
2011-02-11T22:02:00.000
4
0.244919
false
4,974,544
0
0
1
1
I am looking for a simple way to organize stylesheets and scripts in Django. I am relatively new to the framework and language of python. I'm coming from a PHP background. In the world of PHP / Zend there are functions that are implemented with the view/layout object. By including a single line inside your head tag for scripts and for stylsheets you can easily add a stylesheet/script in the view -> method level. I have read the Django Form Media Documentation, but this only pertains to forms needing specific styles and scripts. Any direction?
Use paste.deploy to serve a twisted application
5,240,896
0
1
306
0
python,twisted,wsgi
It is extremely unlikely that trying to do this is going to be worth the effort. paster serve has it's own event loop, threadpool, etc. and Twisted apps expect something quite different. You could try writing your own paster subcommand, but you're probably better off writing a .tac file that serves both apps for use with twistd.
0
0
0
0
2011-02-11T23:18:00.000
1
0
false
4,975,028
0
0
1
1
I'm working on a project that has two parts: A WSGI-enabled web app written with pylons and served with python-paste A python-twisted application that has nothing to do with HTTP or WSGI. I'd like to keep the configuration for both apps in the same configuration file. I'd also like to use paste serve to launch both the WSGI server and the twisted server. Is this possible? Can I configure paste to understand twisted .tac files?
receive data from a python program to animate an object on a webpage
4,979,028
0
0
614
0
python,html
Images are not shown "on your website", they are shown "in your users' browsers". The browser needs to request the animation information from your website, which needs to request it from (wherever it comes from). Ideally, the website will cache the data so that 20 browser requests result in just one website request. How close to realtime is this information? Where does it come from? Is it a service you can run on the webserver? How often does the browser need to be updated? You should look for information on AJAX (letting the browser make asynchronous requests from the website).
0
0
1
0
2011-02-12T16:01:00.000
2
0
false
4,979,005
0
0
1
1
good day stackoverflow! im not sure if any of you has tried this but basically i want to accomplish something like this: - a python program continuously sends data to my website - using that data computations will be made and images on the website are animate so my questions are: 1. what method should i use to communicate python to the website? the easier and simpler the better (tried reading up on django and my nose bled) 2. is javascript the best way to move my images? or is flash better? 3. if flash is better, is it possible to use the input from python and pass it to flash?
web2py and DB transactions
5,443,158
1
2
1,224
1
python,web2py
you can call db.commit() and db.rollback() pretty much everywhere. If you do not and the action does not raise an exception, it commits before returning a response to the client. If it raises an exception and it is not explicitly caught, it rollsback.
0
0
0
0
2011-02-12T17:14:00.000
2
0.099668
false
4,979,392
0
0
1
1
When exactly the database transaction is being commited? Is it for example at the end of every response generation? To explain the question: I need to develop a bit more sophisticated application where I have to control DB transactions less or more manually. Especialy I have to be able to design a set of forms with some complex logics behind the forms (some kind of 'wizard') but the database operations must not be commited until the last form and the confirmation. Of course I could put everything to the session without making any DB change but it's not a solution, the changes are quite complex and realy have to be performed. So the only way is to keep it uncommited. Now back to the question: if I undertand how is it working in web2py it will be easier for me to decide if thats a good framework for me. I am a java and php programmer, I know python but I don't know web2py yet ... If you know any web page when it's explained I also wppreciate. THanks!
How to pass data from Java applet to client side python script?
4,981,088
1
0
969
0
java,javascript,python
If you go for JavaScript I'm assuming it would run in a browser and therefore to communicate with anything else it would make HTTP requests (e.g. POST or GET URLs), so the client/server arrangement is unavoidable. Therefore you would need to turn your Python code into a web application, using something like CherryPy to map URLs to your methods. You could then pass data around using JSON notation.
0
0
0
0
2011-02-12T21:10:00.000
2
0.099668
false
4,980,657
0
0
1
1
I have a python script which does various number-crunching jobs and now need to put a graphical front-end on it (a molecular editor in which a user draws a compound to pass to the script) to allow others in the lab to use it more easily. The available editors are Java applets, standalone Java or written in JavaScript. I would greatly appreciate any advice on the best strategy to put the editor and script together. I really don't want to get into client/server arrangement and envisage a self-contained install on each machine i.e. "client only". Is it better to start off in javascript and pass the output in some way to python and then run the python script from within js. Or (preferably) is there some way to run applets (or standalone java) within python e.g. in Tkinter or some other GUI and "on-click" take the output from the editor into the python script for the crunching bit. Thanks for any pointers - book chapters, useful projects/libraries and links to examples would be great.
I'm learning python and am interested in using it for web-scripting. What frameworkes are out there and do I need one?
4,980,831
2
1
553
0
python,web,web-frameworks,web-scripting
The Python web frameworks have nothing to do with GUIs, and can all be used via the terminal. The benefits of a framework, as you say, are all to do with making your life easier by supplying the components you need to build a website: the main ones are database interaction through an ORM, a templating system, and URL routing. On top of that, the big frameworks also included optional extras like user authentication, administration interface, and so on. Personally I like Django, but your mileage may vary: I would say, though, that whatever you do with Python and the web will require some sort of framework, even if it's one of the absolute minimal ones like Flask which basically do just the routing part. There's simply no point in writing all this stuff from scratch when it's been done for you.
0
0
0
1
2011-02-12T21:30:00.000
4
1.2
true
4,980,756
0
0
1
2
I've been learning python for use in ArcGIS and some other non-web applications. However, now that I've taken on building a personal website I am interested in using it for web development (as it is the only scripting language I currently know). I've noticed that there are a lot of these things called "frameworks", such as Django. From what I understand they are just a collection of packages to save you from re-inventing the wheel but I don't really know how they work. Furthermore, I do not like GUIs, if I need a framework I would like to find one that could be used through a terminal, starts out simple and can be scaled for more complexity when I'm ready. Any advice or ideas on frameworks and why I would want to use one?
I'm learning python and am interested in using it for web-scripting. What frameworkes are out there and do I need one?
4,981,185
0
1
553
0
python,web,web-frameworks,web-scripting
Personnally, I don't use any framework, I write either from scratch on BaseHTTPServer, or using WSGI (with mod_wsgi). It is a bit long to write the skeleton, but I think it is faster (I mean at runtime), there is less constraints, and there is lesser to learn.
0
0
0
1
2011-02-12T21:30:00.000
4
0
false
4,980,756
0
0
1
2
I've been learning python for use in ArcGIS and some other non-web applications. However, now that I've taken on building a personal website I am interested in using it for web development (as it is the only scripting language I currently know). I've noticed that there are a lot of these things called "frameworks", such as Django. From what I understand they are just a collection of packages to save you from re-inventing the wheel but I don't really know how they work. Furthermore, I do not like GUIs, if I need a framework I would like to find one that could be used through a terminal, starts out simple and can be scaled for more complexity when I'm ready. Any advice or ideas on frameworks and why I would want to use one?
I found that I'm trying to write an web app behaves exactly like the django admin. What should I do?
4,982,462
2
1
86
0
python,django
That depends on your motivation. If this is an exercise in sharpening yourself then I suggest reinventing it. Mainly because you learn so much in the process. If the main goal is just to have the functionality then use the django-admin and bolt on whatever you need that it lacks.
0
0
0
0
2011-02-13T04:41:00.000
1
1.2
true
4,982,459
0
0
1
1
This may seem quite a weird question but I'm quite confused right now and don't know what to do. I'm working on an intranet web app using django. Soon I found that almost all features I need are done in django-admin, like adding and editing entries, view and filter items in a list view and so on. The missing parts can be done with some other additional views. Should I just wrap up the admin app or should I re-implement the admin by myself? Or I should use something other than django like GWT or extJS?
Need help parsing html in python3, not well formed enough for xml.etree.ElementTree
4,983,230
4
4
1,545
0
python,parsing,python-3.x,xml.etree
The mismatched tag errors are likely caused by mismatched tags. Browsers are famous for accepting sloppy html, and have made it easy for web page coders to write badly formed html, so there's a lot of it. THere's no reason to believe that creagslist should be immune to bad web page designers. You need to use a grammar that allows for these mismatches. If the parser you are using won't let you redefine the grammar appropriately, you are stuck. (There may be a better Python library for this, but I don't know it). One alternative is to run the web page through a tool like Tidy that cleans up such mismatches, and then run your parser on that.
0
0
1
0
2011-02-13T08:29:00.000
3
0.26052
false
4,983,203
0
0
1
1
I keep getting mismatched tag errors all over the place. I'm not sure why exactly, it's the text on craigslist homepage which looks fine to me, but I haven't skimmed it thoroughly enough. Is there perhaps something more forgiving I could use or is this my best bet for html parsing with the standard library?
What's a safe way to do one-off initialization in Django/mod_wsgi?
4,988,044
2
2
1,280
0
python,django,multithreading,initialization,mod-wsgi
I have my initialization code in a middleware that is called when the first request is served. After the initialization is done, you can raise a MiddlewareNotinuse exception, which causes Django not to execute that middleware again. Remember that because of the way apache and http work, no code will be executed before the first request arrives.
0
0
0
0
2011-02-13T21:26:00.000
3
1.2
true
4,986,986
1
0
1
2
I'm building a Django app that is designed to be multithreaded but reside in a single process running under mod_wsgi. At start of day I need to do various, possibly-lengthy, initialization tasks such as loading a cache of data from the database into a quick lookup dict. I need the intialization to run exactly once before any requests are handled and then to kick off a background thread to periodically update the loaded data. I've tried putting the initialization code inline in a module but I've found that sometimes (if I put load on the server when it's starting) the init code gets executed more than once, screwing everything up. Is there a good place to hook into Django or WSGI to run such init code exactly once before any requests are allowed in? Alternatively, does anyone know under what situations module init code gets executed more than once (particularly in djangp/WSGI-land) or of a good way to stash an "i'm already initialized flag" somewhere?
What's a safe way to do one-off initialization in Django/mod_wsgi?
4,987,126
0
2
1,280
0
python,django,multithreading,initialization,mod-wsgi
Maybe an good old lockfile is a solution for this problem. Not a really elegant solution, but it saves you a lot of headaches in a multithreaded environment.
0
0
0
0
2011-02-13T21:26:00.000
3
0
false
4,986,986
1
0
1
2
I'm building a Django app that is designed to be multithreaded but reside in a single process running under mod_wsgi. At start of day I need to do various, possibly-lengthy, initialization tasks such as loading a cache of data from the database into a quick lookup dict. I need the intialization to run exactly once before any requests are handled and then to kick off a background thread to periodically update the loaded data. I've tried putting the initialization code inline in a module but I've found that sometimes (if I put load on the server when it's starting) the init code gets executed more than once, screwing everything up. Is there a good place to hook into Django or WSGI to run such init code exactly once before any requests are allowed in? Alternatively, does anyone know under what situations module init code gets executed more than once (particularly in djangp/WSGI-land) or of a good way to stash an "i'm already initialized flag" somewhere?
PyRSS2Gen and embedding html in description tag
5,024,582
0
0
578
0
python,rss,cdata
I looked into my problem some more and the problem is that PyRSS2Gen uses python's sax library, which has no concept of CDATA, at least when writing out XML. My solution was just to drop PyRSS2Gen and directly use minidom, which does understand CDATA sections. That did mean some extra lines of code. Once the html text inside my description tag was properly enclosed in a CDATA section, the raw xml looked fine and it also displayed the way I wanted it in 3 RSS readers I tried.
0
0
0
0
2011-02-13T21:58:00.000
2
1.2
true
4,987,182
0
0
1
1
I want to format the content of the description using html tags. When I try to enclose the content in <![CDATA[content<p>here]]> it doesn't work properly, as it escapes some of the brackets, displaying O.K. in some RSS viewers, but displaying the ]]> in others. If I try to avoid the CDATA and use escaped characters throughout, this mostly works, but $lt;p$gt; gets displayed as <p> rather than a new code. Any thoughts?
why doesn't eclipse-python have magic refactor?
5,358,618
1
4
1,299
0
javascript,python,eclipse,refactoring,automated-refactoring
so it turns out that tracing of static information like methods and class hierarchies is perfectly possible in python. PyDev eclipse plugin does it. PyLint plugin attempts to do static analysis even on stuff like dynamic variables by assuming that nothing funky happens at runtime and does a pretty good job.
0
0
0
1
2011-02-14T18:28:00.000
2
1.2
true
4,995,842
1
0
1
1
Eclipse is able to utilize compiled bytecode to enable "magic refactor" functionality--renaming methods, tracing up and down class hierarchies and tracing through method calls. What technical barriers exist that make this harder to do for languages like Python and Javascript?
mod_wsgi for Django on Mac OSX 10.5.8
4,997,873
0
1
407
0
python,django,apache,deployment,mod-wsgi
There is no problem running mod_wsgi on OSX 10.5, a precompiled binary isn't supplied that is all. You would need to compile it from source code, meaning you would need to have XCode installed. Otherwise you wait a week until I get home and I will build a mod_wsgi.so for OSX 10.5 and I will put it up for download. Post to the mod_wsgi mailing list in about a week asking again about it.
0
0
0
0
2011-02-14T21:16:00.000
3
0
false
4,997,366
0
0
1
2
I'm a newbie learning Django, and couldn't get the development server accessible externally. So I'm looking into other deployment options. It seems that mod_wsgi is the way to go (with Apache), but it only supports OSX 10.6+. Are there any alternatives if you own 10.5.8?
mod_wsgi for Django on Mac OSX 10.5.8
5,012,507
0
1
407
0
python,django,apache,deployment,mod-wsgi
Gunicorn is the fastest way to having a production ready web server serving your site that I've found in the Django realm. It is a Python WSGI HTTP Server for UNIX. Steps involved to deploy your site using gunicorn: pip install gunicorn Add 'gunicorn' your installed apps listed in settings.py ./manage.py run_gunicorn -b 127.0.0.1:8001 --daemon
0
0
0
0
2011-02-14T21:16:00.000
3
0
false
4,997,366
0
0
1
2
I'm a newbie learning Django, and couldn't get the development server accessible externally. So I'm looking into other deployment options. It seems that mod_wsgi is the way to go (with Apache), but it only supports OSX 10.6+. Are there any alternatives if you own 10.5.8?
Log Into Website and Scrape Streaming Data
4,999,545
3
0
1,502
0
python,screen-scraping
If the data "refreshes before your eyes" it is probably AJAX (javascript in the page pulling new page-data from the server). There are two ways of approaching this; using Selenium you can wrap an actual browser which will load the page, run the javascript, then you can grab page-bits from the active page. you can look at what the AJAX in the page is doing (how it is asking for updates, what it is getting back) and write python code to emulate that. both take a fair bit of of time and effort to set up; Selenium is a bit more robust, direct python queries is a bit more efficient, YMMV.
0
0
1
0
2011-02-15T02:52:00.000
2
1.2
true
4,999,485
0
0
1
1
I am not really a programmer but am asking this out of general curiosity. I visited a website recently where I logged in, went to a page, and without leaving, data on that page refreshes before my eyes. Is it possible to mimic a browser (I was using Chrome) and log into the site, navigate to a page, and "scrape" that data that is coming in using Python? I would like to store and analyze it. If so, taking this one step further, is it possible to interact with the website? Click a button that I know the name of? Thanks in advance.
Why is Jython much slower than CPython, despite the JVM's advances?
5,000,542
25
42
17,795
0
python,jvm,jython
Keep in mind that IronPython was started by one of the original Jython devs (Jim Huginin) in an attempt to prove that the .NET CLR was a poor platform for dynamic languages. He ended up proving himself wrong and the core of IronPython eventually became the .NET Dynamic Language Runtime (making other dynamic language implementations on .NET, such as IronRuby, significantly easier to build). So there's two major points of difference there: the original .NET CLR devs benefited from additional industry VM experience relative to the early versions of the JVM, allowing them to avoid known problems without backwards compatibility concerns the same applied for Jim in knowing what traps to avoid based on his Jython experience Add in a simple lack of development resources devoted to Jython relative to both CPython and IronPython, and Jython development priorities that focused on bringing it up to feature parity with recent versions of Python moreso than speed optimisations and it's quite understandable that Jython would lag when it came to speed. That said, Jython is similar to both CPython and IronPython, in that the use of better algorithms often trumps poorer performance at microbenchmarks. The JVM/CLR also mean that dropping down to Java or C# for particular components is easier than dropping down into a C extension for CPython (although tools like Cython try to close that gap a bit).
0
0
0
1
2011-02-15T05:55:00.000
1
1.2
true
5,000,360
1
0
1
1
No flame wars please. I am admittedly no fan of Java, but I consider the JVM to be a fairly decent and well-optimized virtual machine. It's JIT-enabled and very close to the common denominator of the prevalent CPU architectures. I'd assume that the CPython runtime would be farther from the metal than a corresponding JVM-based runtime. If my assumptions are correct, could someone explain to me why Jython suffers such a major loss in performance compared to CPython? My initial assumption was that the JVM was simply designed for static languages, and it was difficult to port a dynamic one to it. However, Clojure seems to be an counterexample to that line of argument. On the other hand, IronPython seems to be doing fine. I believe the the lead developer on both projects were/are the same, so the argument that code design and implementation in one is significantly better than the other does not seem likely. I can't figure out what the precise reason is; any help will be appreciated.
Can I deploy Python .pyc files only to Google App Engine?
5,002,563
0
2
2,724
0
python,django,google-app-engine,pyc
Why would you want to do that in the first place? Because your .py files are uploaded to Google infrastructure and can be seen only if you explicitly give permissions. But yes, there is no reason as why uploading only .pyc files should not work. If you try it, in your dev environment, you will find it working just as BaseHTTPServer can take python compiled modules as handlers. Also, recent GAE supports automatic precompilation for python files, which means that as soon as you update your application, the python files can precompiled and served. So, you might have to play with --no_precompilation during appcfg.py upload if there was any expectation to check for .py files at the app engine end.
0
1
0
0
2011-02-15T10:00:00.000
3
0
false
5,002,150
0
0
1
2
I'm working on a project utilizing Django on Google App Engine. I've been asked if some of the code can be deployed as compiled only. So I guess the question is can I upload a .pyc file only that contains the piece of code in question? I've done a basic test with a views.pyc file in an application and things don't work. Is there some configuration or other that I can set to allow Google App Engine to just use the .pyc files?
Can I deploy Python .pyc files only to Google App Engine?
5,002,914
7
2
2,724
0
python,django,google-app-engine,pyc
No, you can't - you can only upload sourcecode. There's no good reason to do this, though: your code will be bytecode-compiled on the servers when needed, and nobody is able to access your code in any case.
0
1
0
0
2011-02-15T10:00:00.000
3
1
false
5,002,150
0
0
1
2
I'm working on a project utilizing Django on Google App Engine. I've been asked if some of the code can be deployed as compiled only. So I guess the question is can I upload a .pyc file only that contains the piece of code in question? I've done a basic test with a views.pyc file in an application and things don't work. Is there some configuration or other that I can set to allow Google App Engine to just use the .pyc files?
Python web-scraping threaded performance
5,462,848
0
2
929
0
python,automated-tests,web-scraping,urllib2,mechanize-python
I actually went without using mechanize and used the Threading module. This allowed for fairly quick transactions, and I also made sure not to have too much inside of each thread. Login information, and getting the webapp in the state necessary before I threaded helped the threads to run shorter and therefore more quickly.
0
0
0
1
2011-02-15T11:22:00.000
3
1.2
true
5,002,986
0
0
1
2
I have a web app that needs both functionality and performance tested, and part of the test suite that we plan on using is already written in Python. When I first wrote this, I used mechanize as my means of web-scraping, but it seems to be too bulky for what I'm trying to do (either that or I'm missing something). The basic layout of what I'm trying to do is as follows. All are objects. User has Comm (used to be the interface between my stuff and mechanize) Comm has Browser (holds my CookieJar, urllib2, and BeautifulSoup objects, used to be mechanize) Browser has Form(s) (used to be mechanize-handled) Now, as far as threading goes, I have that down. Adjustment between dealing with the GIL and having separate instances of Python running will be made as needed, but suggestions will be taken. So what I need to do is thread users hitting the application and doing various things (logging in, filling out forms, submitting forms for processing, etc.) while not making the testing box scream too loudly. My current problem with mechanize seems to be RAM. Part of what's causing the RAM issue is the need for separate browser instances for each user to keep from overwriting the JSESSIONID cookie every time I do something with a different user. Much of this might seem trivial, but I'm trying to run thousands of threads here, so little tweaks can mean a lot. Any input is appreciated.
Python web-scraping threaded performance
5,236,735
0
2
929
0
python,automated-tests,web-scraping,urllib2,mechanize-python
Have you considered Twisted, the asynchronous library, for at least doing interaction with users?
0
0
0
1
2011-02-15T11:22:00.000
3
0
false
5,002,986
0
0
1
2
I have a web app that needs both functionality and performance tested, and part of the test suite that we plan on using is already written in Python. When I first wrote this, I used mechanize as my means of web-scraping, but it seems to be too bulky for what I'm trying to do (either that or I'm missing something). The basic layout of what I'm trying to do is as follows. All are objects. User has Comm (used to be the interface between my stuff and mechanize) Comm has Browser (holds my CookieJar, urllib2, and BeautifulSoup objects, used to be mechanize) Browser has Form(s) (used to be mechanize-handled) Now, as far as threading goes, I have that down. Adjustment between dealing with the GIL and having separate instances of Python running will be made as needed, but suggestions will be taken. So what I need to do is thread users hitting the application and doing various things (logging in, filling out forms, submitting forms for processing, etc.) while not making the testing box scream too loudly. My current problem with mechanize seems to be RAM. Part of what's causing the RAM issue is the need for separate browser instances for each user to keep from overwriting the JSESSIONID cookie every time I do something with a different user. Much of this might seem trivial, but I'm trying to run thousands of threads here, so little tweaks can mean a lot. Any input is appreciated.
sqlautocode : primary key required in tables?
5,292,555
0
0
321
1
python,web-applications,turbogears,turbogears2
We've succeeded in faking sqa if the there's combination of columns on the underlying table that uniquely identify it. If this is your own table and you're not live, add a primary key integer column or something. We've even been able to map an existing legacy table in a database with a) no pk and b) no proxy for a primary key in the other columns. It was Oracle not MySQL but we were able to hack sqa to see Oracle's rowid as a pk, though this is only safe for insert and query...update is not possible since it can't uniquely identify which row it should be updating. But these are ugly hacks so if you can help it, don't go down that road.
0
0
0
0
2011-02-15T12:11:00.000
3
0
false
5,003,475
0
0
1
3
This relates to primary key constraint in SQLAlchemy & sqlautocode. I have SA 0.5.1 & sqlautocode 0.6b1 I have a MySQL table without primary key. sqlautocode spits traceback that "could not assemble any primary key columns". Can I rectify this with a patch sothat it will reflect tables w/o primary key? Thanks, Vineet Deodhar
sqlautocode : primary key required in tables?
5,292,729
0
0
321
1
python,web-applications,turbogears,turbogears2
If the problem is that sqlautocode will not generate your class code because it cannot determine the PKs of the table, then you would probably be able to change that code to fit your needs (even if it means generating SQLA code that doesn't have PKs). Eventually, if you're using the ORM side of SQLA, you're going to need fields defined as PKs, even if the database doesn't explicitly label them as such.
0
0
0
0
2011-02-15T12:11:00.000
3
0
false
5,003,475
0
0
1
3
This relates to primary key constraint in SQLAlchemy & sqlautocode. I have SA 0.5.1 & sqlautocode 0.6b1 I have a MySQL table without primary key. sqlautocode spits traceback that "could not assemble any primary key columns". Can I rectify this with a patch sothat it will reflect tables w/o primary key? Thanks, Vineet Deodhar
sqlautocode : primary key required in tables?
5,003,573
0
0
321
1
python,web-applications,turbogears,turbogears2
I don't think so. How an ORM is suposed to persist an object to the database without any way to uniquely identify records? However, most ORMs accept a primary_key argument so you can indicate the key if it is not explicitly defined in the database.
0
0
0
0
2011-02-15T12:11:00.000
3
0
false
5,003,475
0
0
1
3
This relates to primary key constraint in SQLAlchemy & sqlautocode. I have SA 0.5.1 & sqlautocode 0.6b1 I have a MySQL table without primary key. sqlautocode spits traceback that "could not assemble any primary key columns". Can I rectify this with a patch sothat it will reflect tables w/o primary key? Thanks, Vineet Deodhar
Post-process request event in Pyramid/Pylons
5,011,293
1
3
1,412
0
python,pylons,pyramid
In Pylons, each controller can have a before and after methods you can define that's then called before/after the controller method called. There's also the lib/base.py file which contains the controller call and you could add some custom code there, but it will be called on every request and can be dangerous if your code produces some errors. I'm not sure in Pyramid. If you do things in a custom middleware, you'll have access to the request and response objects, but not other material. You could in theory parse the .ini config for the db settings and such, but if it's really part of the app, I'd stick to a place there.
0
0
0
0
2011-02-15T23:45:00.000
2
0.099668
false
5,010,863
0
0
1
1
Is there an event or some kind of work with middlelayer where the request is already sent to the user, but we still have the information so we can do stuff on the DB later?
Managing two instances of the same GAE application
5,012,278
1
2
74
0
python,google-app-engine
Assuming you are avoiding Nick's suggestion for some particular reason, the next best thing would be to include the copying process in your build system. 1 When you build your deploy target, maven/make/ant/"your favorite build tool" should check out copies of your latest revision from your source control system into separate directories, then copy in or rename the appropriate yaml files. 2 You do have an automated build process, right? If not that should be very high on your list if you are striving for elegance. You are using source control, right? I refuse to entertain the notion that you aren't, because that would be downright ridiculous.
0
1
0
0
2011-02-15T23:52:00.000
3
0.066568
false
5,010,906
0
0
1
1
I have an GAE app, and I deploy it on 2 different domains, and they use separate datastores. However, right now it is done by having two identical folders with different app.yaml configurations. If I make changes I need to copy all files again. Is there an elegant solution for that, like having two app.yaml files in the same folder?
2011 Web Scripting Languages and Dynamic Reloading
5,014,150
4
5
368
0
php,python,ruby,groovy,reloading
I think you're making a bigger deal out of this than it really is. Any application for which it is that important that it never be down for 1/2 a minute (which is all it takes to reboot a server to pick up a file change) really needs to have multiple application server instances in order to handle potential failures of individual instances. Once you have multiple application servers to handle failures, you can also safely restart individual instances for maintenance without causing a problem.
0
0
0
1
2011-02-16T07:56:00.000
2
0.379949
false
5,013,863
0
0
1
1
This has been bugging me for awhile now. In a deployed PHP web application one can upload a changed php script and have the updated file picked up by the web server without having to restart. The problem? Ruby, Groovy, & Python, etc. are all "better" than PHP in terms of language expressiveness, concision, power, ...your-reason-here. Currently, I am really enjoying Groovy (via Grails), but the reality is that the JVM does not do well (at all) with production dynamic reloading of application code. Basically, Permgen out of memory errors are a virtual guarantee, and that means application crash at anytime -- not good. Ruby frameworks seem to have this solved somewhat from what I have read: Passenger has an option to dynamically reload changed files in polled directories on the next request (thus preventing connected users from being disconnected, session lost, etc.). Standalone Python I am not sure about at all; it may, like PHP allow dynamic reloading of python scripts without web server restart. As far as our web work is concerned, invariably clients wind up wanting to make changes to a deployed application regardless of how detailed and well planned the spec was. Telling the client, "sure, we'll implement that [simple] change at 4AM tomorrow [so as to not wreak havoc with connected users]", won't go over too well. As of 2011 where are we at in terms of dynamic reloading and scripting languages? Are we forever doomed, relegated to the convenience of PHP, or the joys of non-PHP and being forced to restart a deployed application? BTW, I am not at all a fan of JSPs, GSPs, and Ruby, Python templating equivalents, despite their reloadability. This is a cake & eat it too thread, where we can make a change to any aspect of the application and not have to restart.
Can my django app act as a header-stripping proxy?
5,014,850
0
2
347
0
python,django,proxy,mp3,soundcloud
I don't think it's possible. It should already be entirely up to the browser. For example Opera asks user weather to open it or download. You could embed them in your site using their Embeded Code. EDIT: Nope you can't even use the link provided by the header since they've worked around hotlinking. Each download is associated to the browser/session so you can't store the real url for the mp3 and link to that.
0
0
0
0
2011-02-16T09:08:00.000
2
0
false
5,014,485
0
0
1
2
Public Soundcloud track urls force a download upon browsing to them by utilizing a Content-Disposition header (I think.. ) which triggers a download for a known mime-type. Is there a way to proxy (create a passthrough for) these urls and strip this header from my request. I want to avoid serving the mp3 myself but I don't want to trigger a download.
Can my django app act as a header-stripping proxy?
5,038,974
2
2
347
0
python,django,proxy,mp3,soundcloud
Technically it is entirely possible that you could request the file from the server and connect that incoming data to an output stream response in your view, thereby allowing you to control the headers that your client's browser receives so that it does not ask them to save the file. I'm going to recommend against this though for a couple of reasons. You mentioned you didn't want to serve the files yourself. Technically you are serving the file in this case, you just aren't storing it. This can be fairly expensive resource wise. Especially network bandwidth. Every mp3 file you share with your user is going to be a sort of double-ding for you. You are going to be both downloading and uploading that entire file, every time. You could cache the mp3 file once it's been requested, but then you aren't just serving the file, you're storing it as well. The file source likely does not want you to do this and could send you a cease and desist letter if they catch wind of it. If they provide a mechanism for you to share their media on your site, they usually have Terms and Conditions that you cannot circumvent that.
0
0
0
0
2011-02-16T09:08:00.000
2
1.2
true
5,014,485
0
0
1
2
Public Soundcloud track urls force a download upon browsing to them by utilizing a Content-Disposition header (I think.. ) which triggers a download for a known mime-type. Is there a way to proxy (create a passthrough for) these urls and strip this header from my request. I want to avoid serving the mp3 myself but I don't want to trigger a download.
Unicode conversion error with django
5,014,866
2
0
267
0
python,django
Check your .po files, in particular the one for the current language; the encoding may be declared incorrectly.
0
0
0
0
2011-02-16T09:46:00.000
1
1.2
true
5,014,847
0
0
1
1
Hi I've upgraded my django version to 1.2.5 and my app stopped working. The error I'm getting now is as follows: Caught DjangoUnicodeDecodeError while rendering: 'ascii' codec can't decode byte 0xc3 in position 13: ordinal not in range(128). You passed in () So far I've been unsuccessful in debugging this problem. The error occurs in: Template error In template /srv/apps/shop_tools/templates/orders/make_order.html, error at line 18 and line 18 is: {% trans 'Order Form' %} With the trans being marked as error causing. Any idea with this strange problem?
Non-blocking http server , java nio , python tornado eventlet
5,049,188
4
4
2,292
0
java,python,http,asynchronous,nonblocking
Nonblocking servers are the best choice provided all your libraries provides nonblocking apis. As mentioned in your second question if a library blocks (eg database lib making a blocking call), the entire process/thread blocks and the system hangs. Not all of the libraries available are asynchronous which makes it difficult to use tornado/eventlet for all usecases. Also in a multi-core box multiple instances of nonblocking servers needs to be started to use the box capacity completly. Tornado/Event servers are similar to java nio based servers. There is one conceptual difference between a Tornado and Eventlet. Tornado follows a reactor pattern where the single process waits for IO(socket) events and dispatches them to appropriate handlers. If handlers are nonblocking, best performance can be expected. Typically code written for these frameworks consists of a series of callbacks making it a bit less readable than a synchronous server .Java NIO servers comes under this category. Eventlet performs the same task but with a cleaner interface. Code can be written as in the case of synchronous server without using callbacks. When an IO is encountered, eventlet schedules another userspace process(not right terminology). Apache webapps are more popular that these because of few reasons It is relatively easy to write synchronous code Not all required libraries are asynchronous. But for writing a chat application which handles lots of connections a multi-threaded server will not scale. You have to use async frameworks like twisted/event/Java NIO.
0
1
0
1
2011-02-17T06:31:00.000
1
0.664037
false
5,025,770
0
0
1
1
Hi I am trying to Understand if tornado/eventlet based http sever are better than threaded sever. While goggling the subject I am seeing that these are single thread event base server which run a single handler function after select/poll/epoll on socket. My first question is that is this tornado/eventlet similar to nio library in java and is a java nio server non-blocking and fast. My second question is that since this event based Server are single thread If one connection blocks on file io or solw client will it hang the entire server My third question is that what is the trade off , if non blocking server is fast why isn't it is more common than apache These questions are related and I would apprecite as I am not understanding these issues correctly Thanks
Google App Engine log username with custom auth
5,035,952
0
1
252
0
python,google-app-engine,logging
Add a single logging.debug call in your authentication code to log the current user. Logs are shown aggregated by request, so you'll always be able to see the user associated with that request.
0
1
0
0
2011-02-17T09:56:00.000
1
0
false
5,027,371
0
0
1
1
I use a custom authentication for my python Google App Engine app. There is a "username" field in the log for every request, which is empty now. Is it possible to add the name of the authenticated user to the log? I would not like to add an "user: %s" % user.name manually to all of my logging.xxx statements. Thanks.
How to set choices in dynamic with Django choicefield?
5,038,378
-1
9
13,979
0
python,django
Similar to maersu's solution, but if you have a ModelForm with a model that has a ForeignKey to another model, you may want to assign to the field's queryset instead of choices.
0
0
0
0
2011-02-17T12:09:00.000
4
-0.049958
false
5,028,731
0
0
1
1
I want to set choices in dynamic. I used __set_choices method but, when request method is POST, is_valid method always return False. if request.method=='POST': _form = MyForm(request.POST) if _form.is_valid(): #something to do
What's the best way to optimise the fixture-loading part of Django tests?
5,029,483
4
9
1,206
0
python,django,testing,performance,fixtures
You may use sqlite in-memory database for tests - it really fast
0
0
0
1
2011-02-17T13:16:00.000
2
0.379949
false
5,029,415
0
0
1
2
my Django tests run really slowly, but it's not the test's fault. At the moment, the whole process takes 14s, but only 0.1s of that is running tests. The first few seconds are creating tables & indexes, the rest is applying the project's many fixtures. What's the best way to deal with this? I think there is a way of specifying which fixtures to load in each test, but I need most of them to do most tests... A solution I think would work is if the tests didn't drop the tables after each run, that way there would be no need to create & populate the database each run-through of the tests. Most tests don't even write to the DB. What's the best way to optimise the fixture-loading part of Django tests? Thanks! (I'm using nose, but otherwise just plain Django and sqlite) EDIT: I should have mentioned that I'm using an in-memory sqlite database. What I'm looking for - specifically - is an optimisation of the fixture-loading section of the test.
What's the best way to optimise the fixture-loading part of Django tests?
5,029,700
4
9
1,206
0
python,django,testing,performance,fixtures
"but I need most of them to do most tests"... Sorry about this, but to speed things up you're going to have to do some thinking. "I think there is a way of specifying which fixtures to load in each test" This is a disturbing thing to read. Have you looked at your tests recently? Your tests do -- specifically -- list the fixtures. You need to minimize that list.
0
0
0
1
2011-02-17T13:16:00.000
2
1.2
true
5,029,415
0
0
1
2
my Django tests run really slowly, but it's not the test's fault. At the moment, the whole process takes 14s, but only 0.1s of that is running tests. The first few seconds are creating tables & indexes, the rest is applying the project's many fixtures. What's the best way to deal with this? I think there is a way of specifying which fixtures to load in each test, but I need most of them to do most tests... A solution I think would work is if the tests didn't drop the tables after each run, that way there would be no need to create & populate the database each run-through of the tests. Most tests don't even write to the DB. What's the best way to optimise the fixture-loading part of Django tests? Thanks! (I'm using nose, but otherwise just plain Django and sqlite) EDIT: I should have mentioned that I'm using an in-memory sqlite database. What I'm looking for - specifically - is an optimisation of the fixture-loading section of the test.
Django manage.py only returning list of subcommands and options
5,032,229
1
0
1,622
0
python,django,manage.py
have you run manage.py runserver and if you have, then try python manage.py runserver?
0
0
0
0
2011-02-17T17:08:00.000
1
1.2
true
5,032,139
0
0
1
1
I'm sure I'm overlooking something very simple, but I've tried multiple times and still run into the same problem. I have installed Python 2.7.1 and Django 1.2.4 on Windows Vista. I create a project using django-admin startproject projectname. It successfully creates the folders and files needed. I then try running manage.py runserver and all I receive in return is the available commands and options for manage.py. What am I missing here? I see no output other than this. Thanks in advance.
In Django, a way for user to upload file to server, then move to Amazon S3?
5,035,338
1
1
714
0
python,django,amazon-s3,wav,waveform
It would make sense to do the work on your side and then upload to Amazon S3. You should be able to use Boto, or any other library by importing the library.
0
0
0
0
2011-02-17T21:59:00.000
2
0.099668
false
5,035,203
0
0
1
1
I have a web project where users are uploading .wav files. I want to generate a waveform image from the .wav file once it's uploaded. But generally for storage, I want to use Amazon S3. Thing is, I want to use something like TimeSide (http://code.google.com/p/timeside/wiki/PythonApi) to generate the waveform image from the .wav file. After speaking with a coder for the TimeSide project, he said it wouldn't be appropriate to generate a waveform image when the .wav file is coming from Amazon S3. So I was thinking it needs to do it's thing as soon as the user uploads the .wav file and then after TimeSide has does it' thing, copy the .wav file and the waveform image over to Amazon S3 and then delete the files from the upload server. Would that make most sense to do it? Can I use Python Boto library for something like this? Or would I have to code my own Django backend?
Designing a Django voting system without using accounts
5,036,260
4
6
1,261
0
python,django,django-forms,django-authentication,voting
To address your concerns: 1: a simple Captcha would probably do the trick, if you google "django captcha", there are a bunch of plugins. I've never used them myself, so I can't say which is the best. 2 & 3: Using Django's sessions addresses both of these problems - with it you could save a cookie on the user's browser to indicate that the person has already voted. This obviously allows people to vote via different browsers or by clearing their cache, so it depends on how important it is that people not be allowed to vote twice. I would imagine that only a small percentage of people would actually think to try clearing their cache, though. As far as I know the only other way to limit users without a sign-in process would be to test IP addresses, but that would violate your second criteria since people on the same network will show up as having the same IP address. If you don't want multiple votes to be as simple as deleting browser cookies, you could also allow facebook or twitter login - the django-socialregistration plugin is pretty well documented and straightforward to implement. Hope that helps!
0
0
0
0
2011-02-17T22:14:00.000
2
1.2
true
5,035,348
0
0
1
1
We are considering implementing a voting system (up, down votes) without using any type of credentials--no app accounts nor OpenID or anything of that sort. Concerns in order: Prevent robot votes Allow individuals under a NAT to vote without overriding/invalidating someone else's vote Preventing (or, at the very least making very difficult for) users to vote more than once My questions: If you've implemented something similar, any tips? Any concerns that perhaps I'm overlooking? Any tools that I should perhaps look into? If you have any questions that would help for you in forming an answer to any of these questions, please ask in the comments!
Can SQLAlchemy do a non-destructive alter of the db comparing the current model with db schema?
5,037,471
0
0
220
1
python,orm,sqlalchemy
Sqlalchemy-migrate (http://packages.python.org/sqlalchemy-migrate/) is intended to help do these types of operations.
0
0
0
0
2011-02-17T23:44:00.000
1
0
false
5,036,118
0
0
1
1
Basically I'm looking for an equivalent of DataMapper.auto_upgrade! from the Ruby world. In other words: change the model run some magic -> current db schema is investigated and changed to reflect the model profit Of course, there are cases when it's impossible for such alteration to be non-desctructive, eg. when you deleted some attribute. But I don't mean such case. I'm looking for a general solution which doesn't get in the way when rapidly prototyping and changing the schema. TIA
Scrapy: RSS control pub_date
12,648,771
0
0
231
0
python,web-crawler,scrapy
I store all data in database as well, and calculate a hash value out of the data. That way you can look up the hash very quickly, and carry out de-dup operation on the fly.
0
0
1
0
2011-02-18T10:50:00.000
2
0
false
5,040,388
0
0
1
2
I'm doing a RSS spider. How do you do for controlling the last crawl date? Right now what was I thinking is this: Put in a control file the last pub_date that I have crawled. Then when the crawl starts, it checks the last pub_date against the new pub_dates. If there are new items, then start crawling, if not, do nothing. How does everyone else resolve this?
Scrapy: RSS control pub_date
5,042,647
1
0
231
0
python,web-crawler,scrapy
I store all data in the database (including last crawl date and post dates) and take all dates I need from database.
0
0
1
0
2011-02-18T10:50:00.000
2
0.099668
false
5,040,388
0
0
1
2
I'm doing a RSS spider. How do you do for controlling the last crawl date? Right now what was I thinking is this: Put in a control file the last pub_date that I have crawled. Then when the crawl starts, it checks the last pub_date against the new pub_dates. If there are new items, then start crawling, if not, do nothing. How does everyone else resolve this?
Chrome extension in python?
9,693,740
7
49
65,662
0
python,google-chrome-extension
Although you mentioned you don't want it to be a hosted app, but this is one typical scenario where a hosted app can do. SciPy is not a package that is easy to deploy. Even if you are writing a installed application based on SciPy, it requires some effort to deploy this dependency. A web application can help here where you put most of the hard-to-deploy dependencies on the server side (which is a one-off thing). And the client side can be really light.
0
0
1
0
2011-02-19T02:23:00.000
7
1
false
5,048,436
0
0
1
1
I would like to create a google chrome extension. Specifically, I'd like to make a packaged app, but not a hosted app. Am I correct in thinking this limits me to JavaScript (and HTML/CSS)? My problem is that I need to do some complex math (singular value decomposition, factor analysis) and I don't want to write algorithms for this in javascript. Python already has libraries for the functions I need (SciPy), but I can't find any indication that I can make a Chrome extension using python. Is this correct? Do I have any other options?