python

How to make an auto-filled and auto-incrementing field in django admin

[Update: Changed question title to be more specific] Sorry if I didn't make the question very well, I can't figure how to do this: class WhatEver(): number = model.IntegerField('Just a Field', default=callablefunction) ... Where callablefunction does this query: from myproject.app.models import WhatEver def callablefunction(): ...

Remote execution of commands using the Django ORM

Can I somehow work with remote databases (if they can do it) with the Django ORM? It is understood that the sitting has spelled out the local database. And periodically to make connection to various external databases and perform any sort of commands such as load dump. ...

simplifying threading in python

I am looking for a way to ease my threaded code. There are a lot of places in my code where I do something like: for arg in array: t=Thread(lambda:myFunction(arg)) t.start() i.e running the same function, each time for different parameters, in threads. This is of course a simplified version of the real code, and usually the co...

What can be the use of SymbolType in Python?

Here's the SymbolType package that adds symbols to Python. Can those who have done anything useful with Lisp/Scheme tell me what how can I take advantage of this type in Python? Can it be used to isolate strings coming from outside (from the web) from internal code? $ sudo easy_install SymbolType $ ipython Unfortunately, you can't us...

python request param

I m working on django view.I m posting a form which has a param name 'service'.Service is checkbox so it will have mulitple values.When i am getting the values of service in my code it is giving me only one value not the array.Here is my sample code {% for ser in allService %} <td > <input type="checkbox" name="service"...

Python copy MySQL table to SQLite3

Hello, I've got a MySQL table with about ~10m rows. I created a parallel schema in SQLite3, and I'd like to copy the table somehow. Using Python seems like an acceptable solution, but this way -- # ... mysqlcursor.execute('SELECT * FROM tbl') rows = mysqlcursor.fetchall() # or mysqlcursor.fetchone() for row in rows: # ... insert r...

Separating HTML into groups using BeautifulSoup when groups are all in the same element

Here's an example: <p class='animal'>cats</p> <p class='attribute'>they meow</p> <p class='attribute'>they have fur</p> <p class='animal'>turtles</p> <p class='attribute'>they don't make noises</p> <p class='attribute'>they have shells</p> If each animal was in a separate element I could just iterate over the elements. That would be g...

django on windows server 2008

does djanog work on windows server 2008? ...

In Python, how do you use decimal module in a script rather than the interpreter?

I'm using Python 2.5.4 and trying to use the decimal module. When I use it in the interpreter, I don't have a problem. For example, this works: >>> from decimal import * >>> Decimal('1.2')+ Decimal('2.3') Decimal("3.5") But, when I put the following code: from decimal import * print Decimal('1.2')+Decimal('2.3') in a se...

How to order by aggregate with conditions on fields of a relation

My code: class School(models.Model): pass class Student(models.Model): school = models.ForeignKey(School) TYPE_CHOICES = ( ('ug', 'Undergraduate'), ('gr', 'Graduate'), ('al', 'Alumnus'), ) type = models.CharField(max_length=2) How do I obtain a QuerySet of Schools ordered by the number of Under...

How to check if phone number entered by user includes country code?

Hi Is there an easy way to check whether a phone number entered by the user includes country code and to validate that the number is correct? I don't use any specific formats, the number itself must be only digits, no ('s, -'s and the like. Is such validation possible without asking user for a country? The trick is that I want to work w...

Plone content type works as folder but not as event

Hi All I have been trying to create a new content type for Plone based on the event type. I followed this tutorial for making content types and successfully created this code for my own content type called "Multimedia". My code works, however the type is based on the folder type. My attempts to change this to be based on the event ...

Forcing to make floating point calculations

In IronPython is there any way to force the expression containing integer values to be calculated as floating point. For instance, I'd like the expression 1/3 to be evaluated as 1./3. with the result 0.333... I need this to make a simple run-time expression calculator within a C# project by means of IronPython. I cannot force us...

Should a modifying class method save itself or be explicity called after the method is called?

Suppose a class has a method that modifies it's internals. Should that method call save on itself before returning or should the save be left to the caller to explicitly save after the modifying method has been called? Example: Explicitly calling save: class Bar(models.Model): def set_foo(self, foo): self.foo = foo bar = ...

Terminating android ASE shell from within the script

I'm using android scripting environment with python (ASE), and I'd like to terminate the shell executing the script when the script terminates. Is there a good way to do this? I have tried executing on the last line: os.system( 'kill %d' % os.getppid() ) but to no avail. ...

Disable all `pylint` 'Convention' messages

Hello, Background I find pylint useful, but I also find it is horrifically undocumented, has painfully verbose output, and lacks an intuitive interface. I'd like to use pylint, but it keeps pumping out an absurd number of pointless 'convention' messages, e.g. C: 2: Line too long (137/80) etc. Question If I could disable these, pylin...

What does a dynamic language like python give you? Coming from a c#/java background. show me the light!

Possible Duplicate: Whats with the love of dynamic Languages I'm coming from a c#/java background i.e. strongly typed, OOP language. I'm very much interested in Python, but I need to learn a little more about the advantages of a dynamic language. What power does it really give me? (in web applications). Can someone outline...

python subprocess hide stdout and wait it to complete

Hi all. I have this code: def method_a(self): command_line = 'somtoolbox GrowingSOM ' + som_prop_path subprocess.Popen(shlex.split(command_line)) ...... def method_b(self): ..... .... and like you all see, method_a has a subprocess that is calling the somtoolbox program. But this program have a long stdout, and I want to ...

How to run python top level/interpreter with file input?

I've always wondered how to do this, it's useful for manual unit testing of individual python scrips. Say I had a python file that did something, and I wanted to run it in the top level, but after it finishes, I want to pick up where it leaves off. I want to be able to use the objects it creates, etc. A simple example, let's say I have...

Selecting Widgets

In Tkinter I'm trying to make it so when a command is run a widget is automatically selected, so that a one may bind events to the newly selected widget. Basically I want it so when I press a button a text widget appears. When it appears normally one would have to click the text widget to facilitate the running of events bound to the t...