WaZaRWiki : PythonTips

GaelReignier :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register :: Hosted by: eNiX

Revision [36424]

Most recent edit made on 2012-04-28 21:07:53 by GaelReignier

Additions:

Interaction with JMS / ApacheMQ

https://twiki.cern.ch/twiki/bin/view/EGEE/MsgTutorial#Setting_message_expiration




Revision [36418]

Edited on 2011-09-06 17:19:46 by GaelReignier

Additions:
To do so, we need to juggle with default dictionary




Revision [36417]

Edited on 2011-09-06 17:18:54 by GaelReignier

Additions:

Nested dictionaries

http://old.nabble.com/creating-a-nested-dictionary-td15061183.html
def deep_default_dict(level):
" This has been done to implement dict with several depths. http://old.nabble.com/creating-a-nested-dictionary-td15061183.html "
if level < 1:
raise ValueError()
result = dict
while level > 1:
result = lambda: defaultdict(result)
level -= 1
return result




Revision [36401]

Edited on 2011-05-30 13:29:04 by GaelReignier

Deletions:

django notes

Create a project
django-admin.py startproject mysite
==Create a new app:==
Several apps can exist in the same project
(bash)
python manage.py startapp polls
Sync the view with the db
python manage.py syncdb
==Run the test server==
(bash)
python manage.py runserver 8080
Show what SQL statements will be generated from models
python manage.py sql appName
==Commit the databases changes to the database==
(bash)
python manage.py syncdb




Revision [36400]

Edited on 2011-05-29 15:17:16 by GaelReignier

Additions:
Commit the databases changes to the database




Revision [36399]

Edited on 2011-05-29 15:16:24 by GaelReignier

Additions:
Show what SQL statements will be generated from models
python manage.py sql appName




Revision [36398]

Edited on 2011-05-29 14:48:31 by GaelReignier

Additions:
Several apps can exist in the same project




Revision [36397]

Edited on 2011-05-29 14:47:23 by GaelReignier

Additions:

django notes

Create a project
django-admin.py startproject mysite


Deletions:

django notes





Revision [36396]

Edited on 2011-05-29 14:46:18 by GaelReignier

Additions:

django notes

Create a new app:
python manage.py startapp polls
==Sync the view with the db==
(bash)
python manage.py syncdb
Run the test server
%%(bash)
python manage.py runserver 8080




Revision [281]

Edited on 2009-02-10 12:30:25 by GaelReignier

Additions:

Not showing the password

import getpass
password = getpass.getpass('Password: ')




Revision [280]

Edited on 2009-02-10 12:14:21 by GaelReignier

Additions:

Parse the input of a CLI script

http://docs.python.org/library/optparse.html




Revision [279]

Edited on 2009-02-10 12:13:47 by GaelReignier

Additions:

use SSH with python

http://www.noah.org/wiki/Pexpect




Revision [253]

Edited on 2008-12-18 14:30:53 by GaelReignier

Additions:
 
(python)
%%(python)




Revision [243]

Edited on 2008-12-14 20:53:30 by GaelReignier

Additions:

Length of an array

myArray=[]
len(myArray)




Revision [242]

Edited on 2008-12-14 19:43:42 by GaelReignier

Additions:

Cast

To cast to string type:
i=0
print str(i)




Revision [208]

Edited on 2008-09-12 11:50:04 by GaelReignier

Additions:

String functions

text=text.encode(charset,'replace')
More info: http://docs.python.org/lib/string-methods.html
charset definition: http://docs.python.org/lib/standard-encodings.html




Revision [202]

Edited on 2008-09-04 20:35:26 by GaelReignier

Additions:

Sending emails in HTML with attached documents

http://code.activestate.com/recipes/473810/




Revision [201]

Edited on 2008-09-04 10:34:42 by GaelReignier

Additions:
If you want to change the way shortcut are bound on your keyboard please check this post: https://lists.berlios.de/pipermail/python-spe-dev/2005-December/000075.html
Basically, shortcuts are defined in Contents/Resources/_spe/shorcuts/OS.py




Revision [198]

Edited on 2008-08-26 10:48:40 by GaelReignier

Additions:

Python Editor

SPE. To install it on mac, you need the python framework and wxpython: http://www.wxpython.org




Revision [192]

The oldest known version of this page was edited on 2008-08-15 13:04:15 by GaelReignier
ITTips
PythonTips

PythonTips

Install MySQLdb connector on Mac OSX

To install the python/MySQL connector on Mac OS X follow the following tutorials:


MySQL connection


You have to create a cursor to connect to the database.
The cursor is created with MySQLdb.connect.
Then in the cursor class, you have a couple of methods:

2 ways to create sql queries and execute them:

sqlInsert = "insert into servers set servername='%s',location='%s',purpose='%s',live='%s',coderelease='%s'" % (servername,location,purpose,live,coderelease)
cursor.execute(sqlInsert)

cursor.execute("insert into servers set servername='%s',location='%s',purpose='%s',live='%s',coderelease='%s'" , (servername,location,purpose,live,coderelease))


The 1st one being the neater!

methods definition

When defining your class methods, you must explicitly list self as the first argument for each method, including init

built in functions

http://docs.python.org/lib/built-in-funcs.html
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki
Page was generated in 0.2735 seconds