Re: Indentifying types?

2009-03-03 Thread Mike Driscoll
On Mar 3, 10:57 am, Oltmans  wrote:
> I'm reading from a file that contains text like
>
> 
> 5
> google_company
> apple_fruit
> pencil_object
> 4
> test_one
> tst_two
> 
>
> When I read the integer 5 I want to make sure it's an integer.
> Likewise, for strings, I want to make sure if something is indeed a
> string. So how do I check types in Python? I want to check following
> types
>
> 1- integers
> 2- strings
> 3- testing types of a particular class
> 4- decimal/floats
>
> Please excuse my ignorance & enlighten me. I will really appreciate
> any help.
>
> Thanks,
> Oltmans

I think when you're reading from a file, it will just read each line
as a string. So you'd probably need to either try casting the line
into something else and catch it in an exception handler or use eval.

The normal way to check types is to use the keyword isinstance or just
use the "type" keyword.

Mike
--
http://mail.python.org/mailman/listinfo/python-list


Indentifying types?

2009-03-03 Thread Oltmans
I'm reading from a file that contains text like


5
google_company
apple_fruit
pencil_object
4
test_one
tst_two


When I read the integer 5 I want to make sure it's an integer.
Likewise, for strings, I want to make sure if something is indeed a
string. So how do I check types in Python? I want to check following
types

1- integers
2- strings
3- testing types of a particular class
4- decimal/floats

Please excuse my ignorance & enlighten me. I will really appreciate
any help.

Thanks,
Oltmans
--
http://mail.python.org/mailman/listinfo/python-list


Re: How best to test functions which use date.today

2009-03-03 Thread Ed Singleton
On Feb 28, 5:54 pm, Lie Ryan  wrote:
> Yuan HOng wrote:
> > HI,
>
> > In my project I have several date related methods which I want tested for
> > correctness. The functions use date.today() in several places. Since this
> > could change every time I run the test, I hope to find someway to fake a
> > date.today.
>
> > For illustration lets say I have a function:
>
> > from datetime import date
> > def today_is_2009():
> >     return date.today().year == 2009
>
> > To test this I would like to write test function like:
>
> > def test_today_is_2009():
> >     set_today(date(2008, 12, 31))
> >     assert today_is_2009() == False
> >     set_today(date(2009,1,1))
> >     assert today_is_2009() == True

Although you can't override today, you should be able to do something
along the lines of:

class MyDate(object):
def __init__(self, today):
self.today = today

my_date = MyDate(date(2009, 11, 12))

date = my_date

This assumes you aren't using anything else from date.  If you are
you'll either have to add that to MyDate or use a proper Mock Object.

Ed

--
http://mail.python.org/mailman/listinfo/python-list


[mod_python] Knowing the encoding of the URI

2009-03-03 Thread Daniel Chiaramello

Hello everybody.

I am using mod_python, and I am confronted with a problem I don't know 
how to solve in an elegant way...


The problem is that I don't know what is the encoding of the 
 strings...


My script runs in China, and I receive requests coded in both "utf-8" 
and "gb18030" encoding...


The way I handle that is the following:

   uri = req.unparsed_uri
  
   try:

   uri_utf8 = uri.decode("utf-8").encode("utf-8")
   found_encoding = (uri_utf8 == uri)
   except:
   found_encoding = False
  
   if not found_encoding:

   uri_gb18030 = ""
   try:
   uri_gb18030 = uri.decode("gb18030").encode("gb18030")
   found_encoding = (uri_gb18030 == uri)
   except:
   found_encoding = False
  
   if found_encoding:

   uri = uri.decode("gb18030").encode("utf-8")
   else:
   raise "### Failed to find encoding for uri '%s'..." % (uri)

I am not very pleased by that.

So, is there a way to know in which encoding the  is 
coded? Is there a better way to determine the encoding?
I noticed the "content_encoding" member of the request, but it is always 
set to None...



Thanks for your attention,
Daniel
--
http://mail.python.org/mailman/listinfo/python-list


Re: siple for in expression

2009-03-03 Thread Mike Driscoll
On Mar 3, 10:05 am, "Matko"  wrote:
> Hello!
>
> Can someone help me to understand the following code:
>
> uv_face_mapping = [[0,0,0,0] for f in faces]
>
> Thank You very much!
>
> Matko from Croatia

That looks like a list comprehension. It basically creates a list by
iterating over some kind of collection. See the following sites for
more info:

http://docs.python.org/tutorial/datastructures.html#list-comprehensions
http://www.secnetix.de/~olli/Python/list_comprehensions.hawk
http://www.network-theory.co.uk/docs/pytut/ListComprehensions.html

Mike
--
http://mail.python.org/mailman/listinfo/python-list


Re: Shared library Python on Mac OS X 64-bit

2009-03-03 Thread Diez B. Roggisch

Uberman schrieb:

Graham Dumpleton wrote:

Why don't you want to use MacOS X Framework libraries? It is the
better installation method.


Because I'm not installing Python, I'm building it.  If I were just interested
in installing Python, I wouldn't care whether it was static or shared libraries.

This is all very specific to my product.  We are not just OS X, but Windows
and Linux as well.  Because of this, we use an SDK/ folder that has all the
third-party dependencies contained within it (in a non-platform way).
Frameworks are OS X-specific.  I build Python within its distribution folder,
and then package that same folder up into an archive that gets deposited into
the SDK/ folder.  The product then builds against that.


A framework isn't much more than a dynamically shared library. So you 
could use it to link against. For example, one can load it using ctypes 
without a hitch.


Diez
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to manage CLOB type with cx_oracle

2009-03-03 Thread Gabriel Genellina
En Tue, 03 Mar 2009 13:33:19 -0200, Loredana   
escribió:



On Mar 3, 1:01 pm, Loredana  wrote:

Hi,

I need to read CLOB field type (it is long text)

if I use this code:

curs.execute(sqlstr)
rows['name_of_columns']     =   name_of_columns
rows['data']                         =   curs.fetchall()

it returns me this values:

test = {'name_of_columns': ['FILENAME', 'CRONTIME', 'SHORT_TAIL',
'LONG_TAIL'], 'data': [('dd','asdds','adadsa',')]}

any ideas?

Thanks

Lory


Hi all,
I success to read one row with the following code:

curs.execute(sqlstr)
name_of_columns =   []
for fieldDesc in curs.description:
name_of_columns.append(fieldDesc[0])
for rows_ in curs.fetchone():
try:
print rows_.read()
except:
print "except. ",rows_

but if I try with fetchmany() it doesn't work
any ideas?


cx_Oracle implements DBAPI 2.0, then you should follow the general  
guidelines in the specification:

http://www.python.org/dev/peps/pep-0249/

LOBs are an extension to DBAPI -- see  
http://cx-oracle.sourceforge.net/html/lob.html and carefully read the  
second note:


"""Note: Internally, Oracle uses LOB locators which are allocated based on  
the cursor array size. Thus, it is important that the data in the LOB  
object be manipulated before another internal fetch takes place. The  
safest way to do this is to use the cursor as an iterator. In particular,  
do not use the fetchall() method. The exception “LOB variable no longer  
valid after subsequent fetch” will be raised if an attempt to access a LOB  
variable after a subsequent fetch is detected."""


--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: getting all HTTP headers from urllib2 Request?

2009-03-03 Thread cgoldberg
> Looking at the httplib sources, the only headers it may add are Host,  
> Accept-Encoding: identity, and Content-Length.


those are exactly the headers I want to capture.
do you know how to get a hold of them from a request using urllib2.

-Corey


--
http://mail.python.org/mailman/listinfo/python-list


Re: easy_install with MySQL-python

2009-03-03 Thread Mike Driscoll
On Mar 3, 7:44 am, Ske  wrote:
> Let me apologise in advance if I’m missing something obvious, I’m still very
> new to this!
>
> I’m attempting to install MySQL-python in Python2.6 on Windows. On running
> "easy_install MySQL-python" I get a "The system cannot find the file
> specified" message. Full output is below:
>
> Searching for MySQL-python
> Readinghttp://pypi.python.org/simple/MySQL-python/
> Readinghttp://sourceforge.net/projects/mysql-python
> Readinghttp://sourceforge.net/projects/mysql-python/
> Best match: MySQL-python 1.2.3b1
> Downloadinghttp://osdn.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python
> -1.2.3b1.tar.gz
> Processing MySQL-python-1.2.3b1.tar.gz
> Running MySQL-python-1.2.3b1\setup.py -q bdist_egg --dist-dir
> c:\docume~1\michae
> ~1\locals~1\temp\easy_install-bmrwgu\MySQL-python-1.2.3b1\egg-dist-tmp-_uhixz
> error: The system cannot find the file specified
>
> I've really no idea how to solve this, and searches turn up nothing of help.
> Any ideas?
> Thanks!
> --

It may be that the egg is incompatible with Python 2.6. Looking at the
last location that easy_install downloads from, I found that there is
no 2.6 egg there (see 
http://sourceforge.net/project/showfiles.php?group_id=22307&package_id=15775).

I've had some goofy issues with compressed files being weird. Try
downloading the source yourself, unzipping it, then navigating to that
folder via the command line and running something like this:

python setup.py install

If your python isn't on the path, you'll have to do something like
this instead:

c:\python26\python.exe setup.py install

Hopefully that will get you going.

Mike
--
http://mail.python.org/mailman/listinfo/python-list


Re: getting all HTTP headers from urllib2 Request?

2009-03-03 Thread Gabriel Genellina
En Tue, 03 Mar 2009 13:44:12 -0200, cgoldberg   
escribió:



I didn't try it, but the Request Class from urllib2 has a method
called, header_items(). That could be what your looking for.


yes, that method only shows you all the headers added by urllib2.

there are other headers that are produced by httplib under the covers
that are added to the outgoing http request.  That is what I am trying
to get at.


Looking at the httplib sources, the only headers it may add are Host,  
Accept-Encoding: identity, and Content-Length.


--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie - pass variable to cscript

2009-03-03 Thread Gabriel Genellina

En Tue, 03 Mar 2009 13:22:20 -0200,  escribió:


On Mar 3, 10:07 am, "Gabriel Genellina" 
wrote:

En Tue, 03 Mar 2009 12:19:22 -0200,  escribió:

> import os
> os.system('cscript.exe /from:wrk-...@zzz.gov /to:plsulli...@zzz.gov'
> "C:\\Program Files\\nasa\\nmail.vbs")

> nmail.vbs works. I need to make it work from a python script. Thanks.

...and the problem is...?

--
Gabriel Genellina


It's not firing off the vbs script. Have I got the syntax correct?
Thanks.

My latest attempt:
vBS = "C:\\Program Files\\nasa\\nmail.vbs"
os.system('cscript /from:wrk-...@pittcountync.gov /
to:plsulli...@pittcountync.gov /sub:TEST /msg:hello ' + vBS)


Usually arguments come after the script name:

vBS = "C:\\Program Files\\nasa\\nmail.vbs"
os.system('cscript "%s" /from:wrk-...@pittcountync.gov  
/to:plsulli...@pittcountync.gov /sub:TEST /msg:hello' % vBS)


But I'd use the subprocess module instead of os.system:

import subprocess
ret = subprocess.call(['cscript', vBS, '/from:...', '/to:...'])

See http://docs.python.org/library/subprocess.html

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: getting all HTTP headers from urllib2 Request?

2009-03-03 Thread cgoldberg
> I didn't try it, but the Request Class from urllib2 has a method
> called, header_items(). That could be what your looking for.


yes, that method only shows you all the headers added by urllib2.

there are other headers that are produced by httplib under the covers
that are added to the outgoing http request.  That is what I am trying
to get at.

-Corey
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to manage CLOB type with cx_oracle

2009-03-03 Thread Loredana
On Mar 3, 1:01 pm, Loredana  wrote:
> Hi,
>
> I need to read CLOB field type (it is long text)
>
> if I use this code:
>
> curs.execute(sqlstr)
> rows['name_of_columns']     =   name_of_columns
> rows['data']                         =   curs.fetchall()
>
> it returns me this values:
>
> test = {'name_of_columns': ['FILENAME', 'CRONTIME', 'SHORT_TAIL',
> 'LONG_TAIL'], 'data': [('dd','asdds','adadsa', 0x2a955bc230>')]}
>
> any ideas?
>
> Thanks
>
> Lory

Hi all,
I success to read one row with the following code:

curs.execute(sqlstr)
name_of_columns =   []
for fieldDesc in curs.description:
name_of_columns.append(fieldDesc[0])
for rows_ in curs.fetchone():
try:
print rows_.read()
except:
print "except. ",rows_

but if I try with fetchmany() it doesn't work
any ideas?

thanks

Loredana
--
http://mail.python.org/mailman/listinfo/python-list


Re: Shared library Python on Mac OS X 64-bit

2009-03-03 Thread Uberman
Graham Dumpleton wrote:
> Why don't you want to use MacOS X Framework libraries? It is the
> better installation method.

Because I'm not installing Python, I'm building it.  If I were just interested
in installing Python, I wouldn't care whether it was static or shared libraries.

This is all very specific to my product.  We are not just OS X, but Windows
and Linux as well.  Because of this, we use an SDK/ folder that has all the
third-party dependencies contained within it (in a non-platform way).
Frameworks are OS X-specific.  I build Python within its distribution folder,
and then package that same folder up into an archive that gets deposited into
the SDK/ folder.  The product then builds against that.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie - pass variable to cscript

2009-03-03 Thread plsullivan1
On Mar 3, 10:07 am, "Gabriel Genellina" 
wrote:
> En Tue, 03 Mar 2009 12:19:22 -0200,  escribió:
>
> > import os
> > os.system('cscript.exe /from:wrk-...@zzz.gov /to:plsulli...@zzz.gov'
> > "C:\\Program Files\\nasa\\nmail.vbs")
>
> > nmail.vbs works. I need to make it work from a python script. Thanks.
>
> ...and the problem is...?
>
> --
> Gabriel Genellina

It's not firing off the vbs script. Have I got the syntax correct?
Thanks.

My latest attempt:
vBS = "C:\\Program Files\\nasa\\nmail.vbs"
os.system('cscript /from:wrk-...@pittcountync.gov /
to:plsulli...@pittcountync.gov /sub:TEST /msg:hello ' + vBS)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Server programming

2009-03-03 Thread Bruno Desthuilliers

koranthala a écrit :
(snip)


Hi Bruno,
   After reading your email, I tried reworking my code so that most of
my logic moves to Models.
   But, most probably because this is my first application
development, I am unable to do so.
   For example:
I have Models A,B, C, D . Now, there is not much model specific
code (preprocessing before updating code inside Models)in it. Rather
most of the code is of the format:
 data received and to be added to D. But for adding to D, check
whether it is already in C - if not add to C and B. etc...


And you don't find it "model specific" ? Man, this is business rules, 
and as such belongs to the models part, not to views. You surely want to 
make sure these rules always apply, don't you ?



   Now, I tried putting this code inside Model D,but it does not seem
to belong there - since it modifies other Models.


And ? Who said a Model (or ModelManager) shouldn't touch other models ?


   Is keeping such code inside views against Django's/Application-
Developments philosophy?


FWIW, I see this antipattern (AnemicDomainModel) way too often in django 
apps. This doesn't make it less of an antipattern.



In that case, where will this go?


It's impossible to say exactly where in the models module without a 
sufficiant knowledge of the domain, rules etc. Sorry, but my crystal 
ball is out for repair.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie - pass variable to cscript

2009-03-03 Thread Gabriel Genellina

En Tue, 03 Mar 2009 12:19:22 -0200,  escribió:


import os
os.system('cscript.exe /from:wrk-...@zzz.gov /to:plsulli...@zzz.gov'
"C:\\Program Files\\nasa\\nmail.vbs")

nmail.vbs works. I need to make it work from a python script. Thanks.


...and the problem is...?

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: getting all HTTP headers from urllib2 Request?

2009-03-03 Thread zdxerr
I didn't try it, but the Request Class from urllib2 has a method
called, header_items(). That could be what your looking for.

On Mar 3, 1:38 am, cgoldberg  wrote:
> I have a Python web client that uses urllib2.  It is easy enough to
> add my own HTTP headers to the outgoing requests. I just create a
> dictionary of the headers I want to add, and pass it to the Request
> initializer.
>
> These custom headers are not all that gets sent.  urllib2 attaches
> headers also.  You can view the headers that urrlib2 adds by looking
> at unredirected_hdrs.
>
> However, these aren't the only HTTP headers that get sent on the
> wire.  Other standard HTTP headers get added to outgoing requests as
> well as the custom ones I explicitly add and urllib2 adds. When I
> sniff the request using Wireshark, I see headers besides the ones I
> added myself.
>
> My question is how do a I get access to *all* of these headers?  I
> want to log every request (including the full set of HTTP headers that
> get sent) that gets sent from my program, and can't figure out how.
> any pointers?
>
> In a nutshell: How do I get *all* the outgoing headers from an HTTP
> request created by urllib2?
>
> - Corey Goldberg

--
http://mail.python.org/mailman/listinfo/python-list


RE: file locking...

2009-03-03 Thread bruce
Hi Dennis...

Thanks for the reply... Here's my solution up to now.. might change in the
future...

The problem:
App has a bunch of clients that need to get a separate/unique list of files
from a master server app. The files are created by the master server
process, and reside on the filesystem behind the server process. (this is a
client/server based app. client sends a request to the server.. the backend
operation of the server fetches the required files, and returns them to the
client app.)

A key issue is that I don't want to run into potential race conditions,
which would result in a given client never being served the files it's
trying to fetch.

Potential Soln:
1) Invoke a form of file locking, with each client processes waiting
   until it gets its lock.
2) Invoke some form of round-robin process, where the master process
   puts files in different dirs, so each client can have a better
   chance of getting a "lock" for the different dir..

Final Soln: (for now)
I decided to cheat!
I realized that since each client process is essentially unique, I can
create a uniqueId (uuid) for each process. Remember, the client app is
hitting the master server/file process via a webservice. So I have each
client send it's uuid to the master server via the webprocess. this
information is appended to a file, which gives me kind of a fifo approach
for creating unique dirs for each client. the server (on the backend) then
reads the fifo file, for the uuid. in getting the uuid for the 'client', a
master cron process then reads the fifo file, and for each uuid in the file,
creates a tmp dir for the uuid. the master cron process then populates this
dir, with the required files for the given client.

on the client side, the client loops through a wait loop, checking to see if
anything is created/placed in its tmp 'uuid' dir.. if files are there, it
fetches the files, and proceeds..

This approach ensures that a client would never run into a situation where
it might never get files where files are available for processing. in the
event there are no files, the client simply sleeps until there are files..
in the event a client requests files via the sending of the uuid, and the
client dies before getting the files, but the master cron had already placed
them in the uuid dir.. there will be a cleanup process to reabsorb those
files back into the system...

thanks to all who gave input/pointers!!

thoughts/comments/etc...



-Original Message-
From: python-list-bounces+bedouglas=earthlink@python.org
[mailto:python-list-bounces+bedouglas=earthlink@python.org]on Behalf
Of Dennis Lee Bieber
Sent: Sunday, March 01, 2009 11:41 AM
To: undisclosed-recipients:
Subject: Re: file locking...


On Sun, 1 Mar 2009 10:00:54 -0800, "bruce" 
declaimed the following in comp.lang.python:

>
> Except in my situation.. the client has no knowledge of the filenaming
> situation, and i might have 1000s of files... think of the FIFO, first in,
> first out.. so i'm loking for a fast solution that would allow me to
create
> groups of say, 500 files, that get batched and processed by the client
> app...
>
My silly thoughts...

Main process creates temp/scratch directories for each subprocess;
spawn each subprocess, passing the directory path to it;
main process then just loops over the files moving them, one at a time,
to one of the temp/scratch directories, probably in cyclic order to
distribute the load;
when main/input directory is empty, sleep then check again (or, if the
OS supports it -- use some directory change notification) for new files.

Each subprocess only sees its files in the applicable temp/scratch
directory.
--
WulfraedDennis Lee Bieber   KD6MOG
wlfr...@ix.netcom.com   wulfr...@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff:   web-a...@bestiaria.com)
HTTP://www.bestiaria.com/
--
http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list


Newbie - pass variable to cscript

2009-03-03 Thread plsullivan1
import os
os.system('cscript.exe /from:wrk-...@zzz.gov /to:plsulli...@zzz.gov'
"C:\\Program Files\\nasa\\nmail.vbs")

nmail.vbs works. I need to make it work from a python script. Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pickle Problem

2009-03-03 Thread Fab86
On Mar 3, 1:02 pm, MRAB  wrote:
> Fab86 wrote:
> > I am getting res1 and res2 etc from this code:
>
> > srch1 = WebSearch(app_id=YahooKey)
> > srch1.query = "avoir site:.al"
> > res1 = srch1.parse_results()
>
> > srch2 = WebSearch(app_id=YahooKey)
> > srch2.query = "avoir site:.fr"
> > res2 = srch2.parse_results()
>
> > After identifying res1, I then use the total_results_available class
> > which saves res1 as an integer.
>
> > This is happening 200 times.
>
> > How could I make a for loop to do this?
>
> langs = ["al", "fr"]
> for lang in langs:
>      srch = WebSearch(app_id=YahooKey)
>      srch.query = "avoir site:.%s" % lang
>      res = srch.parse_results()
>      print >> f, res.total_results_available
>
> You might be able to move the "WebSearch" line out of the loop.
>
> Anyway, have you read through a tutorial?

thanks for this, works perfectly just as I wanted it to.

Again, thanks to everyone who has helped me.

Fabien
--
http://mail.python.org/mailman/listinfo/python-list


Standard CRUD

2009-03-03 Thread timmyt
my buddy and i have created a Standard CRUD (SCRUD) spec that we'd
like to use across projects and frameworks

before we get totally dependent on the pattern, I want to make sure
there's not some better solution out there, or some ideas that will
improve the design

below is the spec we came up with:


SCRUD (Standard CRUD)
=

Overview
---

Standard CRUD is a design pattern for:

* displaying a single instance
* displaying a filterable list of instances

* displaying a form to create a new single instance
* actually creating a new single instance

* displaying a form to update a single instance
* actually updating a single instance

* displaying a form to delete a single instance
* actually deleting a single instance

* displaying a form to perform a bulk insert
* actually performing a bulk insert

* displaying a form to perform a bulk update
* actually performing a bulk update

* displaying a form to perform a bulk delete
* actually performing a bulk delete

The intention is that all methods supported by the model will have
a consistent Class Method Interface - for example any model that
supports bulk insert will have a standard class method to support this
functionality.

Important Considerations


* SCRUD should work the same in an ajax context as well as in a
  traditional page submit
* SCRUD state changing methods should be easily testable using
selenium,
  twill or some other web testing tool in either an ajax or page
submit
  context

General Design


A method performs one distinct action. For example the act of drawing
an update form is different than the act of actually updating an
object
instance.  This helps to enable testability and use in various
contexts.

Page Urls


=
Method  URLWhat it does
=
GETmodel/  gets a list of model instances, using
filters like ?key=value1&key=value2

GETmodel/searchdisplays a search form

GETmodel/iddisplays a readonly instance

GETmodel/edit/id   displays an edit form

POST   model/update/id updates an instance and redirects

GETmodel/createdisplays an insert form

POST   model/insertinserts a new record and redirects

POST   model/delete/id deletes a record and redirects

GETmodel/bulk/edit display a bulk edit ui

POST   model/bulk/update   performs a bulk update and redirect

GETmodel/bulk/create   display a bulk insert form

POST   model/bulk/insert   performs a bulk insert and redirect

POST   model/bulk/delete   performs a bulk delete and redirect
=

--
http://mail.python.org/mailman/listinfo/python-list


easy_install with MySQL-python

2009-03-03 Thread Ske

Let me apologise in advance if I’m missing something obvious, I’m still very
new to this!

I’m attempting to install MySQL-python in Python2.6 on Windows. On running
"easy_install MySQL-python" I get a "The system cannot find the file
specified" message. Full output is below:

Searching for MySQL-python
Reading http://pypi.python.org/simple/MySQL-python/
Reading http://sourceforge.net/projects/mysql-python
Reading http://sourceforge.net/projects/mysql-python/
Best match: MySQL-python 1.2.3b1
Downloading
http://osdn.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python
-1.2.3b1.tar.gz
Processing MySQL-python-1.2.3b1.tar.gz
Running MySQL-python-1.2.3b1\setup.py -q bdist_egg --dist-dir
c:\docume~1\michae
~1\locals~1\temp\easy_install-bmrwgu\MySQL-python-1.2.3b1\egg-dist-tmp-_uhixz
error: The system cannot find the file specified

I've really no idea how to solve this, and searches turn up nothing of help.
Any ideas?
Thanks!
-- 
View this message in context: 
http://www.nabble.com/easy_install-with-MySQL-python-tp22308862p22308862.html
Sent from the Python - python-list mailing list archive at Nabble.com.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Pickle Problem

2009-03-03 Thread MRAB

Fab86 wrote:

I am getting res1 and res2 etc from this code:

srch1 = WebSearch(app_id=YahooKey)
srch1.query = "avoir site:.al"
res1 = srch1.parse_results()

srch2 = WebSearch(app_id=YahooKey)
srch2.query = "avoir site:.fr"
res2 = srch2.parse_results()

After identifying res1, I then use the total_results_available class
which saves res1 as an integer.

This is happening 200 times.

How could I make a for loop to do this?


langs = ["al", "fr"]
for lang in langs:
srch = WebSearch(app_id=YahooKey)
srch.query = "avoir site:.%s" % lang
res = srch.parse_results()
print >> f, res.total_results_available


You might be able to move the "WebSearch" line out of the loop.

Anyway, have you read through a tutorial?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pickle Problem

2009-03-03 Thread Fab86
I am getting res1 and res2 etc from this code:

srch1 = WebSearch(app_id=YahooKey)
srch1.query = "avoir site:.al"
res1 = srch1.parse_results()

srch2 = WebSearch(app_id=YahooKey)
srch2.query = "avoir site:.fr"
res2 = srch2.parse_results()

After identifying res1, I then use the total_results_available class
which saves res1 as an integer.

This is happening 200 times.

How could I make a for loop to do this?

Thanks,

Fabien

On Mar 3, 12:21 pm, odeits  wrote:
> On Mar 3, 4:16 am, Fab86  wrote:
>
>
>
> > Thanks, this seems like a simpler way to do it.
>
> > I plan on recording 200 values to this file from the outcome of 200
> > Yahoo searches. Is there any type of loop I can make to do this or do
> > I have to have a line like "print >> f, res1.total_results_available"
> > 200 times?
>
> > Regards,
>
> > Fabien
>
> > On Mar 3, 12:00 pm, "andrew cooke"  wrote:
>
> > > maybe the following are simpler as they use print
>
> > > if you are using python 2.6 or python 3:
>
> > > >>> from __future__ import print_function
> > > >>> f = open('myfile.txt', 'w')
> > > >>> print(123, file=f)
> > > >>> print(456, file=f)
> > > >>> f.close()
>
> > > alternatively, in python 2.5 or 2.6:
>
> > > >>> f = open('myfile.txt', 'w')
> > > >>> print >> f, 123
> > > >>> print >> f, 456
> > > >>> f.close()
>
> > > andrew
>
> How are you getting res1, res2? in most cases you could just use a for
> loop
>
> for res in results:
>    print >> f, res.total_results_available

--
http://mail.python.org/mailman/listinfo/python-list


Re: Pickle Problem

2009-03-03 Thread odeits
On Mar 3, 4:16 am, Fab86  wrote:
> Thanks, this seems like a simpler way to do it.
>
> I plan on recording 200 values to this file from the outcome of 200
> Yahoo searches. Is there any type of loop I can make to do this or do
> I have to have a line like "print >> f, res1.total_results_available"
> 200 times?
>
> Regards,
>
> Fabien
>
> On Mar 3, 12:00 pm, "andrew cooke"  wrote:
>
> > maybe the following are simpler as they use print
>
> > if you are using python 2.6 or python 3:
>
> > >>> from __future__ import print_function
> > >>> f = open('myfile.txt', 'w')
> > >>> print(123, file=f)
> > >>> print(456, file=f)
> > >>> f.close()
>
> > alternatively, in python 2.5 or 2.6:
>
> > >>> f = open('myfile.txt', 'w')
> > >>> print >> f, 123
> > >>> print >> f, 456
> > >>> f.close()
>
> > andrew
>
>

How are you getting res1, res2? in most cases you could just use a for
loop

for res in results:
   print >> f, res.total_results_available
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pickle Problem

2009-03-03 Thread Fab86
Thanks, this seems like a simpler way to do it.

I plan on recording 200 values to this file from the outcome of 200
Yahoo searches. Is there any type of loop I can make to do this or do
I have to have a line like "print >> f, res1.total_results_available"
200 times?

Regards,

Fabien

On Mar 3, 12:00 pm, "andrew cooke"  wrote:
> maybe the following are simpler as they use print
>
> if you are using python 2.6 or python 3:
>
> >>> from __future__ import print_function
> >>> f = open('myfile.txt', 'w')
> >>> print(123, file=f)
> >>> print(456, file=f)
> >>> f.close()
>
> alternatively, in python 2.5 or 2.6:
>
> >>> f = open('myfile.txt', 'w')
> >>> print >> f, 123
> >>> print >> f, 456
> >>> f.close()
>
> andrew

--
http://mail.python.org/mailman/listinfo/python-list


how to manage CLOB type with cx_oracle

2009-03-03 Thread Loredana
Hi,

I need to read CLOB field type (it is long text)

if I use this code:

curs.execute(sqlstr)
rows['name_of_columns'] =   name_of_columns
rows['data'] =   curs.fetchall()

it returns me this values:

test = {'name_of_columns': ['FILENAME', 'CRONTIME', 'SHORT_TAIL',
'LONG_TAIL'], 'data': [('dd','asdds','adadsa',')]}

any ideas?

Thanks

Lory

--
http://mail.python.org/mailman/listinfo/python-list


Re: Characters aren't displayed correctly

2009-03-03 Thread Hussein B
On Mar 3, 1:54 pm, John Machin  wrote:
> On Mar 3, 10:22 pm, Hussein B  wrote:
>
> > > > Hey,
> > > > I added use_unicode and charset keyword params to the connect() method
>
> > > Hey, that was a brilliant idea -- I was just about to ask you to try
> > >  use_unicode=True, charset="utf8" ... what were the actual values that
> > > you used?
>
> > I didn't supply values for them the first times.
>
> I guessed that! I was referring to the fact that you didn't tell us
> what values you did eventually supply that made it generate seemingly
> reasonable Arabic letters in unicode!!  Was it charset="utf8" that did
> the trick?
>
>
>
>
>
Yes, it is utf8

> > > Let's suppose that you used charset="" ... as far as I can tell,
> > > not being a mysqldb user myself, this means that your data tables and/
> > > or your default connection don't use  as an encoding. If so, this
> > > might be an issue you might like to take up with whoever created the
> > > database that you are using.
>
> > > > and I got the following:
> > > > u'\u062f\u062e\u0648\u0644 \u0633\u0631\u064a\u0639
> > > > \u0634\u0647\u0631'
> > > > So characters are getting converted successfully.
>
> > > I guess so -- U+06nn sure are Arabic characters :-)
>
> > > However as suggested above, "converted from what?" might be worth
> > > pursuing if you like to understand what is going on instead of just
> > > applying magic recipes ;-)
>
> > > > Well, using the previous recipe for sending the 
> > > > mail:http://code.activestate.com/recipes/473810/
> > > > I got the following error:
>
> > > > Traceback (most recent call last):
> > > >   File "HtmlMail.py", line 52, in 
> > > >     s.sendmail(sender, receiver , msg.as_string())
>
> > > [big snip]
>
> > > > _handle_text
> > > >     self._fp.write(payload)
> > > > UnicodeEncodeError: 'ascii' codec can't encode characters in position
> > > > 115-118: ordinal not in range(128)
>
> > > > Again, any ideas guys? :)
>
> > > That recipe appears to have been written by an ascii bigot for ascii
> > > bigots :-(
>
> > > Try reading the docs for email.charset (that's the charset module in
> > > the email package).
>
> > Every thing is working now, I did the following:
> > t = MIMEText(markup.encode('utf-8'), 'html', 'utf-8')
> > Thank you all guys and especially you John, I owe you a HUGE bottle of
> > beer :D
>
> Thanks for the kind thought, but beer decreases grey-cell count and
> increases girth ... I don't need any assistance with those matters :-)
>
> Cheers,
> John

No problem John.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pickle Problem

2009-03-03 Thread Fab86
Fantastic, just what I was looking for Andrew.

Many thanks,

Fabien

On Mar 3, 11:50 am, "andrew cooke"  wrote:
> Fab86 wrote:
> > I am wanting to store the integers in a file so that I can then run it
> > through some software without having to edit it. Will json enable me
> > to do this?
>
> no.  ignore json - it is for something else entirely.
>
> all you need to do is to write the numbers out to a file:
>
> f = open('file.txt', 'w')
> f.write('%d\n' % 123)
> f.write('%d\n' % 456)
> f.close()
>
> for an explanation of the "%" 
> seehttp://docs.python.org/library/stdtypes.html#index-1680
>
> the '\n' is a newline character so that after each number a new line is
> started.
>
> andrew
>
> > Thanks again,
>
> > Fabien
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
>

--
http://mail.python.org/mailman/listinfo/python-list


Re: RichCompare and RichCompareBool

2009-03-03 Thread Gabriel Genellina
En Tue, 03 Mar 2009 04:42:02 -0200, Aaron Brady   
escribió:



Also, did not receive Gabriel's post.


That's because I replied a month ago - and probably you had no idea what I  
was talking about by that time.


(Sorry, I inadvertedly set the clock one month back. You didn't miss  
anything)


--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: Pickle Problem

2009-03-03 Thread andrew cooke

maybe the following are simpler as they use print


if you are using python 2.6 or python 3:

>>> from __future__ import print_function
>>> f = open('myfile.txt', 'w')
>>> print(123, file=f)
>>> print(456, file=f)
>>> f.close()


alternatively, in python 2.5 or 2.6:

>>> f = open('myfile.txt', 'w')
>>> print >> f, 123
>>> print >> f, 456
>>> f.close()


andrew



--
http://mail.python.org/mailman/listinfo/python-list


Re: Characters aren't displayed correctly

2009-03-03 Thread John Machin
On Mar 3, 10:22 pm, Hussein B  wrote:
> > > Hey,
> > > I added use_unicode and charset keyword params to the connect() method
>
> > Hey, that was a brilliant idea -- I was just about to ask you to try
> >  use_unicode=True, charset="utf8" ... what were the actual values that
> > you used?
>
> I didn't supply values for them the first times.

I guessed that! I was referring to the fact that you didn't tell us
what values you did eventually supply that made it generate seemingly
reasonable Arabic letters in unicode!!  Was it charset="utf8" that did
the trick?

>
>
>
> > Let's suppose that you used charset="" ... as far as I can tell,
> > not being a mysqldb user myself, this means that your data tables and/
> > or your default connection don't use  as an encoding. If so, this
> > might be an issue you might like to take up with whoever created the
> > database that you are using.
>
> > > and I got the following:
> > > u'\u062f\u062e\u0648\u0644 \u0633\u0631\u064a\u0639
> > > \u0634\u0647\u0631'
> > > So characters are getting converted successfully.
>
> > I guess so -- U+06nn sure are Arabic characters :-)
>
> > However as suggested above, "converted from what?" might be worth
> > pursuing if you like to understand what is going on instead of just
> > applying magic recipes ;-)
>
> > > Well, using the previous recipe for sending the 
> > > mail:http://code.activestate.com/recipes/473810/
> > > I got the following error:
>
> > > Traceback (most recent call last):
> > >   File "HtmlMail.py", line 52, in 
> > >     s.sendmail(sender, receiver , msg.as_string())
>
> > [big snip]
>
> > > _handle_text
> > >     self._fp.write(payload)
> > > UnicodeEncodeError: 'ascii' codec can't encode characters in position
> > > 115-118: ordinal not in range(128)
>
> > > Again, any ideas guys? :)
>
> > That recipe appears to have been written by an ascii bigot for ascii
> > bigots :-(
>
> > Try reading the docs for email.charset (that's the charset module in
> > the email package).
>
> Every thing is working now, I did the following:
> t = MIMEText(markup.encode('utf-8'), 'html', 'utf-8')

> Thank you all guys and especially you John, I owe you a HUGE bottle of
> beer :D

Thanks for the kind thought, but beer decreases grey-cell count and
increases girth ... I don't need any assistance with those matters :-)

Cheers,
John
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pickle Problem

2009-03-03 Thread andrew cooke
Fab86 wrote:
> I am wanting to store the integers in a file so that I can then run it
> through some software without having to edit it. Will json enable me
> to do this?

no.  ignore json - it is for something else entirely.

all you need to do is to write the numbers out to a file:

f = open('file.txt', 'w')
f.write('%d\n' % 123)
f.write('%d\n' % 456)
f.close()

for an explanation of the "%" see
http://docs.python.org/library/stdtypes.html#index-1680

the '\n' is a newline character so that after each number a new line is
started.

andrew

> Thanks again,
>
> Fabien
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


--
http://mail.python.org/mailman/listinfo/python-list


Re: Pickle Problem

2009-03-03 Thread Hrvoje Niksic
Fab86  writes:

> when trying to pickle them they are displayed like this:
>
> I14
> .I15200
> .I86000
> .
>
> But in console simply printing these attributes I get:
>
> 14
> 15200
> 86000
>

> Can anyone help?

Can you describe the problem in some detail?  Everything seems to be
working fine, AFAICT; files written with pickle.dump() are supposed to
be read back with pickle.load().  Is that not working for you, or (I
am guessing) would you prefer a human-readable/editable on-disk
representation of your data?
--
http://mail.python.org/mailman/listinfo/python-list


Re: removing duplication from a huge list.

2009-03-03 Thread bearophileHUGS
odeits:
> Although this is true, that is more of an answer to the question "How
> do i remove duplicates from a huge list in Unix?".

Don't you like cygwin?

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


yaml for persistence

2009-03-03 Thread Paul
class User(object):
def __init__(self, uid):
   self.uid = uid
   self.__dict__.update(yaml.load(str('uid')+'.yaml'))

def save(self):
f=open(str(self.uid)+'.yaml')
yaml.dump(self.__dict__, f)



is there a better way to persist using Yaml

Paul
http://bidegg.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to find all completely connected sub-graphs?

2009-03-03 Thread odeits
On Mar 2, 11:26 pm, Hyunchul Kim  wrote:
> Dear Odeits,
>
> Yes, I meant directly connected to each other.
>
> Thanks.
>
> Hyunchul
>
> odeits wrote:
> > On Mar 2, 10:35 pm, Hyunchul Kim  wrote:
>
> >> Hi, all,
>
> >> How can I find all "completely connected subgraphs" in a graph when node
> >> and edge data are available?
>
> >> "completely connected subgraph" is a group, all members of which are
> >> connected to each other.
>
> >> Thanks,
>
> >> Hyunchul
>
> > Do you mean all of the member are directly connected to each other?
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
>

I would start by creating sets for every node in your graph that are
made up of the node and all of its edges. Then you can use the
issubset to filter down your collection.

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

The idea is a node find its completely connected subset. once you have
done this, you can remove all of those nodes from the universal set
and chose another node. repeat until the universal set is empty.
Remember the smallest completely connected subset is an individual
node.

That should be a good enough starting point to figure out an alg that
works for you.

Cheers.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Get bound method by name

2009-03-03 Thread Graham Breed

Johannes Bauer wrote:

Hello group,

I'm looking for a Python function but have forgotten it's name.
Essentially what I want is:

class Foo():
def bar(self):
pass

x = Foo()
y = x.MAGIC("bar")
print(y)
>

So the question is: How is the magic function called which returns me
the bound method of a class instance by its name? I know there was a way
but just can't remember...


y = getattr(x, "bar")
--
http://mail.python.org/mailman/listinfo/python-list


Re: Characters aren't displayed correctly

2009-03-03 Thread Hussein B
On Mar 3, 12:21 pm, John Machin  wrote:
> On Mar 3, 8:49 pm, Hussein B  wrote:
>
>
>
> > On Mar 3, 11:05 am, Hussein B  wrote:
>
> > > On Mar 2, 5:40 pm, John Machin  wrote:
>
> > > > On Mar 3, 1:50 am, Hussein B  wrote:
>
> > > > > On Mar 2, 4:31 pm, John Machin  wrote:> On Mar 
> > > > > 2, 7:30 pm, Hussein B  wrote:
>
> > > > > > > On Mar 1, 4:51 pm, Philip Semanchuk  wrote:
>
> > > > > > > > On Mar 1, 2009, at 8:31 AM, Hussein B wrote:
>
> > > > > > > > > Hey,
> > > > > > > > > I'm retrieving records from MySQL database that contains non 
> > > > > > > > > english
> > > > > > > > > characters.
>
> > > > > > Can you reveal which language???
>
> > > > > Arabic
>
> > > > > > > > > Then I create a String that contains HTML markup and column 
> > > > > > > > > values
> > > > > > > > > from the previous result set.
> > > > > > > > > +
> > > > > > > > > markup = u'''.'''
> > > > > > > > > for row in rows:
> > > > > > > > >     markup = markup + '' + row['id']
> > > > > > > > > markup = markup + '
> > > > > > > > > +
> > > > > > > > > Then I'm sending the email according to this tip:
> > > > > > > > >http://code.activestate.com/recipes/473810/
> > > > > > > > > Well, the email contains ? characters for each non 
> > > > > > > > > english ones.
> > > > > > > > > Any ideas?
>
> > > > > > > > There's so many places where this could go wrong and you 
> > > > > > > > haven't  
> > > > > > > > narrowed down the problem.
>
> > > > > > > > Are the characters stored in the database correctly?
>
> > > > > > > Yes they are.
>
> > > > > > How do you KNOW that they are stored correctly? What makes you so
> > > > > > sure?
>
> > > > > Because MySQL Query Browser displays them correctly, in addition I use
> > > > > BIRT as the reporting system and it shows them correctly.
>
> > > > > > > > Are they stored consistently (i.e. all using the same encoding, 
> > > > > > > > not  
> > > > > > > > some using utf-8 and others using iso-8859-1)?
>
> > > > > > > Yes.
>
> > > > > > So what is the encoding used to store them?
>
> > > > > Tables are created with UTF-8 encoding option
>
> > > > > > > > What are you getting out of the database? Is it being converted 
> > > > > > > > to  
> > > > > > > > Unicode correctly, or at all?
>
> > > > > > > I don't know, how to make sure of this point?
>
> > > > > > You could show us some of the output from the database query. As 
> > > > > > well
> > > > > > as
> > > > > >    print the_output
> > > > > > you should
> > > > > >    print repr(the_output)
> > > > > > and show us both, and also tell us what you *expect* to see.
>
> > > > > The result of print repr(row['name']) is '??? ??'
> > > > > The '?' characters are supposed to be Arabic characters.
>
> > > > Are you expecting 3 Arabic characters, a space, and then 6 Arabic
> > > > characters?
>
> > > > We now have some interesting evidence: row['name'] is NOT a unicode
> > > > object -- otherwise the print would show u'??? ??'; it's a str
> > > > object.
>
> > > > So: A utf8-encoded string is being decoded to unicode, and then re-
> > > > encoded to some other encoding, using the "replace" (with "?") error-
> > > > handling method. That shouldn't be hard to spot! It's about time you
> > > > showed us the code you are using to extract the data from the
> > > > database, including the print statements you have put in.
>
> > > This is how I retrieve the data:
>
> > > db = MySQLdb.connect(host = "127.0.0.1", port = 3306, user =
> > > "username",
> > >                          passwd = "passwd", db = "reporting")
> > > cr = db.cursor(MySQLdb.cursors.DictCursor)
> > > cr.execute(sql)
> > > rows = cr.fetchall()
>
> > > Thanks all for your nice help.
>
> > Hey,
> > I added use_unicode and charset keyword params to the connect() method
>
> Hey, that was a brilliant idea -- I was just about to ask you to try
>  use_unicode=True, charset="utf8" ... what were the actual values that
> you used?

I didn't supply values for them the first times.

> Let's suppose that you used charset="" ... as far as I can tell,
> not being a mysqldb user myself, this means that your data tables and/
> or your default connection don't use  as an encoding. If so, this
> might be an issue you might like to take up with whoever created the
> database that you are using.
>
> > and I got the following:
> > u'\u062f\u062e\u0648\u0644 \u0633\u0631\u064a\u0639
> > \u0634\u0647\u0631'
> > So characters are getting converted successfully.
>
> I guess so -- U+06nn sure are Arabic characters :-)
>
> However as suggested above, "converted from what?" might be worth
> pursuing if you like to understand what is going on instead of just
> applying magic recipes ;-)
>
> > Well, using the previous recipe for sending the 
> > mail:http://code.activestate.com/recipes/473810/
> > I got the following error:
>
> > Traceback (most recent call last):
> >   File "HtmlMail.py", line 52, in 
> >     s.sendmail(sender, receiver , msg.as_string())
>
> [big snip]
>
> > _handl

Re: Get bound method by name

2009-03-03 Thread John Machin
On Mar 3, 10:12 pm, Johannes Bauer  wrote:
> Hello group,
>
> I'm looking for a Python function but have forgotten it's name.
> Essentially what I want is:
>
> class Foo():
>         def bar(self):
>                 pass
>
> x = Foo()
> y = x.MAGIC("bar")
> print(y)
> >
>
> So the question is: How is the magic function called which returns me
> the bound method of a class instance by its name? I know there was a way
> but just can't remember...

getattr(x, "bar")

--
http://mail.python.org/mailman/listinfo/python-list


Re: Get bound method by name

2009-03-03 Thread Chris Rebert
On Tue, Mar 3, 2009 at 3:12 AM, Johannes Bauer  wrote:
> Hello group,
>
> I'm looking for a Python function but have forgotten it's name.
> Essentially what I want is:
>
> class Foo():
>        def bar(self):
>                pass
>
> x = Foo()
> y = x.MAGIC("bar")

getattr() is the function you seek.

y = getattr(x, "bar")

> print(y)
> >

Cheers,
Chris

-- 
Shameless self-promotion:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pickle Problem

2009-03-03 Thread Fab86
On Mar 3, 10:34 am, Chris Rebert  wrote:
> On Tue, Mar 3, 2009 at 1:52 AM, Fab86  wrote:
> > Hello,
>
> > I am new to using Python and am looking at exporting some of my code
> > into a seperate document.
>
> > The code I am using for the pickle is:
>
> > file = open('testdoc.txt', 'w')
>
> > pickle.dump(res1.total_results_available,file)
> > pickle.dump(res2.total_results_available,file)
> > pickle.dump(res3.total_results_available,file)
> > file.close()
>
> > res1.total_results_available and others are simply integers which are
> > recalled from the Yahoo Search API and they print fine cmd or console
> > but when trying to pickle them they are displayed like this:
>
> > I14
> > .I15200
> > .I86000
> > .
>
> That's the contents of testdoc.txt after your program has written data
> to it using pickle. With pickle's default settings, the version of the
> format it uses (specifically, the oldest version) looks like that
> (integers in base-10 prefixed with 'I', entries separated by a newline
> and a period). It's *NOT* intended NOR guaranteed to be human-readable
> (indeed, with alternate settings it uses a binary format which is
> /unintelligible/ to the causal viewer). For human-readable
> serialization, use the `json` module (among other possibilities).
>
>
>
> > But in console simply printing these attributes I get:
>
> > 14
> > 15200
> > 86000
>
> That's normal. Pickle reads in the data from the file and deserializes
> it back into the proper Python objects.
>
>
>
> > Can anyone help?
>
> There's no problem to be solved here, just some explaining in order to
> deepen your understanding.
>
> Cheers,
> Chris
>
> --
> Shameless self-promotion:http://blog.rebertia.com

Thank you for your reply.

Are you saying to take a look at the python json module then?

I am wanting to store the integers in a file so that I can then run it
through some software without having to edit it. Will json enable me
to do this?

Thanks again,

Fabien
--
http://mail.python.org/mailman/listinfo/python-list


Get bound method by name

2009-03-03 Thread Johannes Bauer
Hello group,

I'm looking for a Python function but have forgotten it's name.
Essentially what I want is:

class Foo():
def bar(self):
pass

x = Foo()
y = x.MAGIC("bar")
print(y)
>

So the question is: How is the magic function called which returns me
the bound method of a class instance by its name? I know there was a way
but just can't remember...

Thanks in advance,
Kind regards,
Johannes

-- 
"Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
verlästerung von Gott, Bibel und mir und bewusster Blasphemie."
 -- Prophet und Visionär Hans Joss aka HJP in de.sci.physik
 <48d8bf1d$0$7510$54022...@news.sunrise.ch>
--
http://mail.python.org/mailman/listinfo/python-list


Re: New User - Using tutorial and Docs - POST returns 302 Found

2009-03-03 Thread Gabriel Genellina

En Tue, 03 Mar 2009 04:13:46 -0200, JohnV  escribió:


Thanks for your suggestion, but I am not able to get it to work for
me.

My original script was:

f = open('C:\Users\Owner\Desktop\mydata.txt', 'r')
read_data = f.read()
f.close()


\ is the escape character in Python. You must double it when you want it  
to stand by itself:

'C:\\Users\\Owner\\Desktop\\mydata.txt'
Alternatively, use a raw string: r'C:\Users\Owner\Desktop\mydata.txt'
The same applies to the output file.


I imported urllib2 However, this the scriot does not seem to work for
me for two reasons

First the url that recieves the post is
http://www.thenational.us/pages/start/test/getpost.html so I belive
the "url line" should read:
url = "http://www.thenational.us:80/pages/start/test/getpost.html";


Yes!


I do not know how to capture the text that is displayed in the
interpreter window when I run the program, as the window closes after
the script is run.  How do I keep the window open so I can read what
messages are printed there?


Open a command prompt first (Start > Run > type "CMD" and enter), go to  
the directory where your script is located (type: CD c:\some\directory)  
and then you're ready to execute it using: python scriptname.py



Finally, do I need conn.close() with the new code you suggested?


No, it should be response.close() instead. The whole script is now:


import httplib, urllib, urllib2

f = open(r'C:\Users\Owner\Desktop\mydata.txt', 'r')
read_data = f.read()
f.close()

params = urllib.urlencode({'textarea1': read_data})
headers = {"Content-type": "application/x-www-form-urlencoded",
   "Accept": "text/plain"}
url = "http://www.thenational.us:80/pages/start/test/getpost.html";
req = urllib2.Request(url, params, headers)
response = urllib2.urlopen(req)
data = response.read()
response.close()
print data

f = open(r'C:\Users\Owner\Desktop\pydata.txt', 'a')
f.write(data)
f.close()


--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: Pickle Problem

2009-03-03 Thread Chris Rebert
On Tue, Mar 3, 2009 at 1:52 AM, Fab86  wrote:
> Hello,
>
> I am new to using Python and am looking at exporting some of my code
> into a seperate document.
>
> The code I am using for the pickle is:
>
> file = open('testdoc.txt', 'w')
>
> pickle.dump(res1.total_results_available,file)
> pickle.dump(res2.total_results_available,file)
> pickle.dump(res3.total_results_available,file)
> file.close()
>
> res1.total_results_available and others are simply integers which are
> recalled from the Yahoo Search API and they print fine cmd or console
> but when trying to pickle them they are displayed like this:
>
> I14
> .I15200
> .I86000
> .

That's the contents of testdoc.txt after your program has written data
to it using pickle. With pickle's default settings, the version of the
format it uses (specifically, the oldest version) looks like that
(integers in base-10 prefixed with 'I', entries separated by a newline
and a period). It's *NOT* intended NOR guaranteed to be human-readable
(indeed, with alternate settings it uses a binary format which is
/unintelligible/ to the causal viewer). For human-readable
serialization, use the `json` module (among other possibilities).

>
> But in console simply printing these attributes I get:
>
> 14
> 15200
> 86000

That's normal. Pickle reads in the data from the file and deserializes
it back into the proper Python objects.

>
> Can anyone help?

There's no problem to be solved here, just some explaining in order to
deepen your understanding.

Cheers,
Chris

-- 
Shameless self-promotion:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Touchscreen GUI for PyKaraoke - Job in London

2009-03-03 Thread alext
Hi, I am looking for someone to write a touchscreen GUI for PyKaraoke
(http://www.kibosh.org/pykaraoke/). Looking for someone based in or
around London with a lot of experience of Python and Linux who willl
be able to complete this project quickly. Knowledge of sound and video
processing on Linux a bonus. Please contact me for further details.
Thanks, Alex
--
http://mail.python.org/mailman/listinfo/python-list


Re: HTTPError... read the response body?

2009-03-03 Thread Diez B. Roggisch

Stuart Davenport schrieb:

On Mar 2, 11:50 pm, Wojtek Walczak  wrote:

On Mon, 2 Mar 2009 14:29:12 -0800 (PST), Stuart Davenport wrote:

Hi,


I am trying to connect to a web service but I am getting HTTP 400, I
am not too concerned about the HTTP error - but what I'd like to know
if there is anyway I can read the response body in the HTTP 400 or 500
case? Does the HTTPError allow this? or the urllib2 in anyway?

HTTP error 400 means 'bad request', so it's almost certainly
your mistake.


#url, body, headers
rq = urllib2.Request(args[1], args[3], headers)

Is args[1] a valid URL? And are you sure that you want to send
something to the web serwer? By specifying the second argument
(args[3]) you're asking python to send HTTP "POST" request,
not "GET".

--
Regards,
Wojtek Walczak,http://tosh.pl/gminick/


Hi Wojtek,

Yes, the args[1] is a valid url (I've printed it out to check) and
thats correct, I do want to initiate a POST request by passing over
the SOAP Envelope in the request. All I'd like to know if there is
anyway to read the body of an HTTP Error, so for instance, if I were
to recieve a 404 - I'd like to see the content that the server returns
with a 404 error.


HTTPError.read() works for me.

Diez
--
http://mail.python.org/mailman/listinfo/python-list


Re: Characters aren't displayed correctly

2009-03-03 Thread John Machin
On Mar 3, 8:49 pm, Hussein B  wrote:
> On Mar 3, 11:05 am, Hussein B  wrote:
>
>
>
> > On Mar 2, 5:40 pm, John Machin  wrote:
>
> > > On Mar 3, 1:50 am, Hussein B  wrote:
>
> > > > On Mar 2, 4:31 pm, John Machin  wrote:> On Mar 2, 
> > > > 7:30 pm, Hussein B  wrote:
>
> > > > > > On Mar 1, 4:51 pm, Philip Semanchuk  wrote:
>
> > > > > > > On Mar 1, 2009, at 8:31 AM, Hussein B wrote:
>
> > > > > > > > Hey,
> > > > > > > > I'm retrieving records from MySQL database that contains non 
> > > > > > > > english
> > > > > > > > characters.
>
> > > > > Can you reveal which language???
>
> > > > Arabic
>
> > > > > > > > Then I create a String that contains HTML markup and column 
> > > > > > > > values
> > > > > > > > from the previous result set.
> > > > > > > > +
> > > > > > > > markup = u'''.'''
> > > > > > > > for row in rows:
> > > > > > > >     markup = markup + '' + row['id']
> > > > > > > > markup = markup + '
> > > > > > > > +
> > > > > > > > Then I'm sending the email according to this tip:
> > > > > > > >http://code.activestate.com/recipes/473810/
> > > > > > > > Well, the email contains ? characters for each non english 
> > > > > > > > ones.
> > > > > > > > Any ideas?
>
> > > > > > > There's so many places where this could go wrong and you haven't  
> > > > > > > narrowed down the problem.
>
> > > > > > > Are the characters stored in the database correctly?
>
> > > > > > Yes they are.
>
> > > > > How do you KNOW that they are stored correctly? What makes you so
> > > > > sure?
>
> > > > Because MySQL Query Browser displays them correctly, in addition I use
> > > > BIRT as the reporting system and it shows them correctly.
>
> > > > > > > Are they stored consistently (i.e. all using the same encoding, 
> > > > > > > not  
> > > > > > > some using utf-8 and others using iso-8859-1)?
>
> > > > > > Yes.
>
> > > > > So what is the encoding used to store them?
>
> > > > Tables are created with UTF-8 encoding option
>
> > > > > > > What are you getting out of the database? Is it being converted 
> > > > > > > to  
> > > > > > > Unicode correctly, or at all?
>
> > > > > > I don't know, how to make sure of this point?
>
> > > > > You could show us some of the output from the database query. As well
> > > > > as
> > > > >    print the_output
> > > > > you should
> > > > >    print repr(the_output)
> > > > > and show us both, and also tell us what you *expect* to see.
>
> > > > The result of print repr(row['name']) is '??? ??'
> > > > The '?' characters are supposed to be Arabic characters.
>
> > > Are you expecting 3 Arabic characters, a space, and then 6 Arabic
> > > characters?
>
> > > We now have some interesting evidence: row['name'] is NOT a unicode
> > > object -- otherwise the print would show u'??? ??'; it's a str
> > > object.
>
> > > So: A utf8-encoded string is being decoded to unicode, and then re-
> > > encoded to some other encoding, using the "replace" (with "?") error-
> > > handling method. That shouldn't be hard to spot! It's about time you
> > > showed us the code you are using to extract the data from the
> > > database, including the print statements you have put in.
>
> > This is how I retrieve the data:
>
> > db = MySQLdb.connect(host = "127.0.0.1", port = 3306, user =
> > "username",
> >                          passwd = "passwd", db = "reporting")
> > cr = db.cursor(MySQLdb.cursors.DictCursor)
> > cr.execute(sql)
> > rows = cr.fetchall()
>
> > Thanks all for your nice help.
>
> Hey,
> I added use_unicode and charset keyword params to the connect() method

Hey, that was a brilliant idea -- I was just about to ask you to try
 use_unicode=True, charset="utf8" ... what were the actual values that
you used?

Let's suppose that you used charset="" ... as far as I can tell,
not being a mysqldb user myself, this means that your data tables and/
or your default connection don't use  as an encoding. If so, this
might be an issue you might like to take up with whoever created the
database that you are using.

> and I got the following:
> u'\u062f\u062e\u0648\u0644 \u0633\u0631\u064a\u0639
> \u0634\u0647\u0631'
> So characters are getting converted successfully.

I guess so -- U+06nn sure are Arabic characters :-)

However as suggested above, "converted from what?" might be worth
pursuing if you like to understand what is going on instead of just
applying magic recipes ;-)


> Well, using the previous recipe for sending the 
> mail:http://code.activestate.com/recipes/473810/
> I got the following error:
>
> Traceback (most recent call last):
>   File "HtmlMail.py", line 52, in 
>     s.sendmail(sender, receiver , msg.as_string())

[big snip]

> _handle_text
>     self._fp.write(payload)
> UnicodeEncodeError: 'ascii' codec can't encode characters in position
> 115-118: ordinal not in range(128)
>
> Again, any ideas guys? :)

That recipe appears to have been written by an ascii bigot for ascii
bigots :-(

Try reading the docs for email.charset (that's the charset module 

[ANN] pysqlite 2.5.2

2009-03-03 Thread Gerhard Häring
pysqlite 2.5.2 released
===

Release focus: minor bugfixes, minor new features.

pysqlite is a DB-API 2.0-compliant database interface for SQLite.

SQLite is a in-process library that implements a self-contained,
serverless, zero-configuration, transactional SQL database
engine.

Go to http://pysqlite.org/ for downloads, online documentation and
for reporting bugs.

Changes
===

- Like on Connection.rollback(), Connection.commit() now resets
  all statements associated to the connection, so that the
  commit() should always succeed (unless other connections create
  trouble).

- pysqlite used to deliver bogus results on cursors that still
  have unfetched data when a rollback() was done on the
  connection. A commit() or rollback() now puts the cursor into a
  "reset" state. If you try to fetch data after commit() or
  rollback() you will now get an InterfaceError exception instead
  of bogus data.

- For better DB-API compliance, operations on closed cursors now
  raise exceptions.

- Add amalgamation directory to include path when building
  statically against amalgamation files.

  Otherwise, building against the amalgamation only worked if you
  already had the SQLite3 header files in the search path. Like
  on my development system ;-)

- Made sure HAVE_LOAD_EXTENSION is not defined twice. Also made
  sure that it's OFF if the OMIT macro is defined.

- Fixed check if non-UTF8 strings are acceptable input. The check
  was wrong for OptimizedUnicode. Also added the missing tests
  for this feature.

- Wrap routine sqlite3_load_extension as method load_extension of
  the Connection object.

Compatibility
=

The fact that commit() and rollback() now reset all associated cursors
changes
the behaviour of pysqlite. Some code that previously worked will now raise
InterfaceError exceptions. OTOH the code did not really *work*, because it
produced wrong results.

In previous pysqlite versions:

>>> from pysqlite2 import dbapi2 as sqlite3
>>> con = sqlite3.connect(":memory:")
>>> con.executescript("create table t(c); insert into t(c) values (1);
insert into t(c) values (2); insert into t(c) values (3);")

>>> cur = con.cursor()
>>> cur.execute("insert into t values (4)")

>>> cur.execute("select * from t")

>>> con.rollback ()
>>> print cur.fetchall ()
[(1,), (1,), (2,), (3,)]

  ^ ^

!! Notice the duplicate rows with values (1,) !! This code produced
wrong results.


With this release, the last cur.fetchall() will raise an exception:

>>> print cur.fetchall ()
Traceback (most recent call last):
  File "", line 1, in 
  pysqlite2.dbapi2.InterfaceError: Cursor needed to be reset because of
commit/rollback and can no longer be fetched from.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Upgrade Python on a Mac

2009-03-03 Thread Graham Dumpleton
On Mar 3, 8:53 am, Rey Bango  wrote:
> Hi,
>
> I'd like to upgrade the installed version of Python that came standard
> on OS X (Leopard) with either 2.6.1 or 3.0.1. Before I stick my foot
> in it, I just wanted to get a better understanding of the process.
>
> If I download the disk image installer from 
> here:http://www.python.org/download/
> will it allow me to upgrade my existing version or is it more involved
> (eg: making a new build).
>
> I've looked through the python.org page for upgrade instructions for a
> Mac and haven't found it.
>
> Any help would be appreciated.

Beware of the official Python binary installers for MacOS X if wanting
to do Python web development.

Based on feedback these installers have only been compiled for 32 bit
architectures. This makes them useless if you want to run mod_python
or mod_wsgi with Apache that comes with MacOS X as it runs as 64 bit
and relies on the Python framework having 64 bit, which these
installers do not provide.

If this is going to affect you, build from source code. Configure
options required would be, as an example:

./configure --prefix=/usr/local/python-3.0  \
 --enable-framework=/usr/local/python-3.0/frameworks \
 --enable-universalsdk=/ MACOSX_DEPLOYMENT_TARGET=10.5 \
 --with-universal-archs=all

Note that not all MacPorts installers have been both 32/64 bit either.
Not sure if they have fixed this issue.

Graham

--
http://mail.python.org/mailman/listinfo/python-list


Pickle Problem

2009-03-03 Thread Fab86
Hello,

I am new to using Python and am looking at exporting some of my code
into a seperate document.

The code I am using for the pickle is:

file = open('testdoc.txt', 'w')

pickle.dump(res1.total_results_available,file)
pickle.dump(res2.total_results_available,file)
pickle.dump(res3.total_results_available,file)
file.close()

res1.total_results_available and others are simply integers which are
recalled from the Yahoo Search API and they print fine cmd or console
but when trying to pickle them they are displayed like this:

I14
.I15200
.I86000
.

But in console simply printing these attributes I get:

14
15200
86000

Can anyone help?

Many thanks,

Fabien
--
http://mail.python.org/mailman/listinfo/python-list


Re: Characters aren't displayed correctly

2009-03-03 Thread Hussein B
On Mar 3, 11:05 am, Hussein B  wrote:
> On Mar 2, 5:40 pm, John Machin  wrote:
>
>
>
> > On Mar 3, 1:50 am, Hussein B  wrote:
>
> > > On Mar 2, 4:31 pm, John Machin  wrote:> On Mar 2, 
> > > 7:30 pm, Hussein B  wrote:
>
> > > > > On Mar 1, 4:51 pm, Philip Semanchuk  wrote:
>
> > > > > > On Mar 1, 2009, at 8:31 AM, Hussein B wrote:
>
> > > > > > > Hey,
> > > > > > > I'm retrieving records from MySQL database that contains non 
> > > > > > > english
> > > > > > > characters.
>
> > > > Can you reveal which language???
>
> > > Arabic
>
> > > > > > > Then I create a String that contains HTML markup and column values
> > > > > > > from the previous result set.
> > > > > > > +
> > > > > > > markup = u'''.'''
> > > > > > > for row in rows:
> > > > > > >     markup = markup + '' + row['id']
> > > > > > > markup = markup + '
> > > > > > > +
> > > > > > > Then I'm sending the email according to this tip:
> > > > > > >http://code.activestate.com/recipes/473810/
> > > > > > > Well, the email contains ? characters for each non english 
> > > > > > > ones.
> > > > > > > Any ideas?
>
> > > > > > There's so many places where this could go wrong and you haven't  
> > > > > > narrowed down the problem.
>
> > > > > > Are the characters stored in the database correctly?
>
> > > > > Yes they are.
>
> > > > How do you KNOW that they are stored correctly? What makes you so
> > > > sure?
>
> > > Because MySQL Query Browser displays them correctly, in addition I use
> > > BIRT as the reporting system and it shows them correctly.
>
> > > > > > Are they stored consistently (i.e. all using the same encoding, not 
> > > > > >  
> > > > > > some using utf-8 and others using iso-8859-1)?
>
> > > > > Yes.
>
> > > > So what is the encoding used to store them?
>
> > > Tables are created with UTF-8 encoding option
>
> > > > > > What are you getting out of the database? Is it being converted to  
> > > > > > Unicode correctly, or at all?
>
> > > > > I don't know, how to make sure of this point?
>
> > > > You could show us some of the output from the database query. As well
> > > > as
> > > >    print the_output
> > > > you should
> > > >    print repr(the_output)
> > > > and show us both, and also tell us what you *expect* to see.
>
> > > The result of print repr(row['name']) is '??? ??'
> > > The '?' characters are supposed to be Arabic characters.
>
> > Are you expecting 3 Arabic characters, a space, and then 6 Arabic
> > characters?
>
> > We now have some interesting evidence: row['name'] is NOT a unicode
> > object -- otherwise the print would show u'??? ??'; it's a str
> > object.
>
> > So: A utf8-encoded string is being decoded to unicode, and then re-
> > encoded to some other encoding, using the "replace" (with "?") error-
> > handling method. That shouldn't be hard to spot! It's about time you
> > showed us the code you are using to extract the data from the
> > database, including the print statements you have put in.
>
> This is how I retrieve the data:
>
> db = MySQLdb.connect(host = "127.0.0.1", port = 3306, user =
> "username",
>                          passwd = "passwd", db = "reporting")
> cr = db.cursor(MySQLdb.cursors.DictCursor)
> cr.execute(sql)
> rows = cr.fetchall()
>
> Thanks all for your nice help.

Hey,
I added use_unicode and charset keyword params to the connect() method
and I got the following:
u'\u062f\u062e\u0648\u0644 \u0633\u0631\u064a\u0639
\u0634\u0647\u0631'
So characters are getting converted successfully.
Well, using the previous recipe for sending the mail:
http://code.activestate.com/recipes/473810/
I got the following error:

Traceback (most recent call last):
  File "HtmlMail.py", line 52, in 
s.sendmail(sender, receiver , msg.as_string())
  File "/usr/lib/python2.5/email/message.py", line 131, in as_string
g.flatten(self, unixfrom=unixfrom)
  File "/usr/lib/python2.5/email/generator.py", line 84, in flatten
self._write(msg)
  File "/usr/lib/python2.5/email/generator.py", line 109, in _write
self._dispatch(msg)
  File "/usr/lib/python2.5/email/generator.py", line 135, in _dispatch
meth(msg)
  File "/usr/lib/python2.5/email/generator.py", line 201, in
_handle_multipart
g.flatten(part, unixfrom=False)
  File "/usr/lib/python2.5/email/generator.py", line 84, in flatten
self._write(msg)
  File "/usr/lib/python2.5/email/generator.py", line 109, in _write
self._dispatch(msg)
  File "/usr/lib/python2.5/email/generator.py", line 135, in _dispatch
meth(msg)
  File "/usr/lib/python2.5/email/generator.py", line 201, in
_handle_multipart
g.flatten(part, unixfrom=False)
  File "/usr/lib/python2.5/email/generator.py", line 84, in flatten
self._write(msg)
  File "/usr/lib/python2.5/email/generator.py", line 109, in _write
self._dispatch(msg)
  File "/usr/lib/python2.5/email/generator.py", line 135, in _dispatch
meth(msg)
  File "/usr/lib/python2.5/email/generator.py", line 178, in
_handle_text
self._fp.write(payload)
UnicodeEncodeError: 

Re: HTTPError... read the response body?

2009-03-03 Thread Stuart Davenport
On Mar 2, 11:50 pm, Wojtek Walczak  wrote:
> On Mon, 2 Mar 2009 14:29:12 -0800 (PST), Stuart Davenport wrote:
>
> Hi,
>
> > I am trying to connect to a web service but I am getting HTTP 400, I
> > am not too concerned about the HTTP error - but what I'd like to know
> > if there is anyway I can read the response body in the HTTP 400 or 500
> > case? Does the HTTPError allow this? or the urllib2 in anyway?
>
> HTTP error 400 means 'bad request', so it's almost certainly
> your mistake.
>
> >                         #url, body, headers
> >                         rq = urllib2.Request(args[1], args[3], headers)
>
> Is args[1] a valid URL? And are you sure that you want to send
> something to the web serwer? By specifying the second argument
> (args[3]) you're asking python to send HTTP "POST" request,
> not "GET".
>
> --
> Regards,
> Wojtek Walczak,http://tosh.pl/gminick/

Hi Wojtek,

Yes, the args[1] is a valid url (I've printed it out to check) and
thats correct, I do want to initiate a POST request by passing over
the SOAP Envelope in the request. All I'd like to know if there is
anyway to read the body of an HTTP Error, so for instance, if I were
to recieve a 404 - I'd like to see the content that the server returns
with a 404 error.
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to find all completely connected sub-graphs?

2009-03-03 Thread andrew cooke

if you mean "strongly connected components" then see
http://en.wikipedia.org/wiki/Strongly_connected_component.  there is no
need to invent a solution; standard methods already exist.

andrew


Hyunchul Kim wrote:
> Hi, all,
>
> How can I find all "completely connected subgraphs" in a graph when node
> and edge data are available?
>
> "completely connected subgraph" is a group, all members of which are
> connected to each other.
>
> Thanks,
>
> Hyunchul
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


--
http://mail.python.org/mailman/listinfo/python-list


Re: how to find all completely connected sub-graphs?

2009-03-03 Thread wwwayne
Hi Hyunchul,

On Tue, 03 Mar 2009 15:35:11 +0900, Hyunchul Kim
 wrote:

>Hi, all,
>
>How can I find all "completely connected subgraphs" in a graph when node 
>and edge data are available?
>
>"completely connected subgraph" is a group, all members of which are 
>connected to each other.

Since you're asking here I suspect you want (to develop) a python
solution, but I have seen only solutions for a few special cases.

This is the well-known graph theoretic "maximal cliques" problem (dual
to the maximal independent sets problem) which is NP-complete so
heuristics are in order for large examples.

The most commonly used algorithm was (and perhaps still is, though I
haven't kept up with this area) Bierstone's Algorithm, which I believe
was unpublished so available only in discussion papers and the like. I
compared it and two other common (at the time) algorithms, implemented
in FORTRAN (as it was then), for a MSc project a U. Waterloo in 1970,
and probably still have a copy somewhere...

It may well also be in the update (ACM membership or site access
trough a univeristy library or similar is required to get the full
text of most of these):

Corrections to Bierstone's Algorithm for Generating Cliques
http://portal.acm.org/citation.cfm?id=321694.321698

and:

Algorithm 457: finding all cliques of an undirected graph
http://portal.acm.org/citation.cfm?doid=362342.362367

The classic reference for such clustering techniques is:

An Analysis of Some Graph Theoretical Cluster Techniques
http://portal.acm.org/citation.cfm?id=321608&dl=GUIDE&coll=GUIDE&CFID=25034057&CFTOKEN=54219245

If you want to find all cliques of a fixed size, then there are more
efficient algorithms, and there's a very recent paper on these:

Virginia Vassilevska, Efficient algorithms for clique problems,
Information Processing Letters, v.109 n.4, p.254-257, January, 2009 
http://portal.acm.org/citation.cfm?id=1480733&dl=GUIDE&coll=GUIDE&CFID=25034057&CFTOKEN=54219245

I hope these leads help!

wwwayne

>Thanks,
>
>Hyunchul
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Characters aren't displayed correctly

2009-03-03 Thread Hussein B
On Mar 2, 5:40 pm, John Machin  wrote:
> On Mar 3, 1:50 am, Hussein B  wrote:
>
>
>
> > On Mar 2, 4:31 pm, John Machin  wrote:> On Mar 2, 
> > 7:30 pm, Hussein B  wrote:
>
> > > > On Mar 1, 4:51 pm, Philip Semanchuk  wrote:
>
> > > > > On Mar 1, 2009, at 8:31 AM, Hussein B wrote:
>
> > > > > > Hey,
> > > > > > I'm retrieving records from MySQL database that contains non english
> > > > > > characters.
>
> > > Can you reveal which language???
>
> > Arabic
>
> > > > > > Then I create a String that contains HTML markup and column values
> > > > > > from the previous result set.
> > > > > > +
> > > > > > markup = u'''.'''
> > > > > > for row in rows:
> > > > > >     markup = markup + '' + row['id']
> > > > > > markup = markup + '
> > > > > > +
> > > > > > Then I'm sending the email according to this tip:
> > > > > >http://code.activestate.com/recipes/473810/
> > > > > > Well, the email contains ? characters for each non english ones.
> > > > > > Any ideas?
>
> > > > > There's so many places where this could go wrong and you haven't  
> > > > > narrowed down the problem.
>
> > > > > Are the characters stored in the database correctly?
>
> > > > Yes they are.
>
> > > How do you KNOW that they are stored correctly? What makes you so
> > > sure?
>
> > Because MySQL Query Browser displays them correctly, in addition I use
> > BIRT as the reporting system and it shows them correctly.
>
> > > > > Are they stored consistently (i.e. all using the same encoding, not  
> > > > > some using utf-8 and others using iso-8859-1)?
>
> > > > Yes.
>
> > > So what is the encoding used to store them?
>
> > Tables are created with UTF-8 encoding option
>
> > > > > What are you getting out of the database? Is it being converted to  
> > > > > Unicode correctly, or at all?
>
> > > > I don't know, how to make sure of this point?
>
> > > You could show us some of the output from the database query. As well
> > > as
> > >    print the_output
> > > you should
> > >    print repr(the_output)
> > > and show us both, and also tell us what you *expect* to see.
>
> > The result of print repr(row['name']) is '??? ??'
> > The '?' characters are supposed to be Arabic characters.
>
> Are you expecting 3 Arabic characters, a space, and then 6 Arabic
> characters?
>
> We now have some interesting evidence: row['name'] is NOT a unicode
> object -- otherwise the print would show u'??? ??'; it's a str
> object.
>
> So: A utf8-encoded string is being decoded to unicode, and then re-
> encoded to some other encoding, using the "replace" (with "?") error-
> handling method. That shouldn't be hard to spot! It's about time you
> showed us the code you are using to extract the data from the
> database, including the print statements you have put in.

This is how I retrieve the data:

db = MySQLdb.connect(host = "127.0.0.1", port = 3306, user =
"username",
 passwd = "passwd", db = "reporting")
cr = db.cursor(MySQLdb.cursors.DictCursor)
cr.execute(sql)
rows = cr.fetchall()

Thanks all for your nice help.
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to find all completely connected sub-graphs?

2009-03-03 Thread odeits
On Mar 3, 12:07 am, Andre Engels  wrote:
> On Tue, Mar 3, 2009 at 7:35 AM, Hyunchul Kim  wrote:
> > How can I find all "completely connected subgraphs" in a graph when node and
> > edge data are available?
>
> > "completely connected subgraph" is a group, all members of which are
> > connected to each other.
>
> Here is an algorithm I came up with in a few minutes of thinking,
> complexity O(N*SN) with N being the number of nodes in the graph and
> SN the sum of the nodes in each connected subgraph (there may well be
> faster algorithms, but then you'd probably have to ask someone who
> either already knows it, or spends significantly more time on it than
> I did) - in pseudocode, but translating pseudocode into Python is an
> easy thing to do:
>
> Let N be the nodes in the graph.
> A = {emptyset}      # that is, a set containing only the empty set in
> the beginning
> foreach node k in N:
>     foreach set a in A:
>         if k is connected to each node in a:
>             add k+{a} to A   # in such a way that it's not included in
> the loop for the current node k
>
> The completely connected subgraphs are the subgraphs for which the set
> of nodes in the subgraph is in A.
>
> --
> André Engels, andreeng...@gmail.com

Seems to me the definition of the completely connected graph is:

for a given node N with an edge set of E

the complete graph is the intersection of all of the edge sets
belonging to each element in E

so assuming you have a dictionary that is d[Node] = list(edgeNodes)

for Node, EdgeNodes in d:
   connectedGraph = set(EdgeNodes}
   connectedGraph.add(Node)
   for EdgeNode in EdgeNodes:
 EdgeSet = set(d[EdgeNode])
 EdgeSet.add(EdgeNode)
 connectedGraph.intersectionUpdate( EdgeSet)
   yield connectedGraph

Code is untested but i think illustrates my theory.

Regards,
--
http://mail.python.org/mailman/listinfo/python-list


Re: yaml for persistence

2009-03-03 Thread Diez B. Roggisch

Paul schrieb:

class User(object):
def __init__(self, uid):
   self.uid = uid
   self.__dict__.update(yaml.load(str('uid')+'.yaml'))

def save(self):
f=open(str(self.uid)+'.yaml')
yaml.dump(self.__dict__, f)



is there a better way to persist using Yaml

Paul
http://bidegg.com


AFAIK Yaml already supports persisting python objects:

>>> from yaml import dump
>>> class Foo(object):
...def __init__(self, name):
...self.name = name
...
>>> f = Foo('bar')
>>> dump(f)
'!!python/object:__main__.Foo {name: bar}\n'
>>>


And if you want to write your own persistence, I'd do that as yaml and 
pickle do as a generic function that supports the pickle protocol.


http://docs.python.org/library/pickle.html#the-pickle-protocol

Diez
--
http://mail.python.org/mailman/listinfo/python-list


Re: Upgrade Python on a Mac

2009-03-03 Thread Diez B. Roggisch

Wes James schrieb:

On Mon, Mar 2, 2009 at 2:53 PM, Rey Bango  wrote:

Hi,

I'd like to upgrade the installed version of Python that came standard
on OS X (Leopard) with either 2.6.1 or 3.0.1. Before I stick my foot
in it, I just wanted to get a better understanding of the process.


I'd recommend you put your new versions in to /usr/local


Certainly not. Instead, create framework builds. These install 
themselves under /Library/Frameworks, instead of 
/System/Library/Frameworks, where the shipped python lives.


Not using a FW-build will cost you a lot of features OSX-specific.

Diez
--
http://mail.python.org/mailman/listinfo/python-list


qt, gtk, wx for py3 ?

2009-03-03 Thread Peter Billam
I've been trying (newbie warning still on) tkinter with python3.0,
and I'm getting to that stage where I'm beginning to think there
must be a better a way to do this...  But I'm unsure if the
big names Qt, Gtk and Wx are available for Py3 yet - e.g.
http://pypi.python.org/pypi?:action=browse&c=533&show=all doesn't
seem to show any... What's the gossip on these toolkits for Py3 ?

Regards,  Peter

-- 
Peter Billam   www.pjb.com.auwww.pjb.com.au/comp/contact.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe automatic upgrades of a program while it is running, is that possible?

2009-03-03 Thread Patrick Mullen
On Mon, Mar 2, 2009 at 6:56 PM, Maxim Khitrov  wrote:
> - Show quoted text -
> On Mon, Mar 2, 2009 at 9:18 PM, William Heath  wrote:
>> Hi All,
>> I am using py2exe to create a windows executable.  I am curious if anyone
>> knows a way to automatically upgrade a py2exe windows executable while it is
>> running.  Is that possible?  If so how?  If it isn't possible, what is the
>> next best thing?  Also, if it is not available using py2exe is it available
>> in other languages/solutions your aware of?
>> -Tim

Here's what I did, which works really well.  The main script imports
other python modules which do the real work of the program.  It is
only a few lines long and looks something like this:

import main
main.run()


There is more stuff there, imports etc to help py2exe find everything,
but that's the basic idea.  Then, to upgrade the program, all I have
to do is replace the modules which are in a subfolder.  (And be
careful to reload them, which has its own considerations).

I do some wonky stuff in my build script to delete my main modules
from library.zip since its easier to replace them outside of that, you
could also use the skip-archive option to not use the .zip file at
all.

You really can't replace an exe itself while its running, I would
avoid that as much as possible.  Workarounds to do this are highly
prone to error.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Server programming

2009-03-03 Thread koranthala
On Feb 24, 1:02 am, Bruno Desthuilliers
 wrote:
> koranthalaa écrit :
>
> > Hi,
> >       Is server programming in Python procedure oriented or object
> > oriented?
>
> It's how you want it to be.
>
> >       I have this question because lately I am asked to make a medium
> > complex web program (extremely database oriented) using Django. When I
> > used to do application programs earlier (in Python itself),  the whole
> > thing being object oriented came out easily in programming. So, I was
> > able to use different patterns etc for programming and the whole thing
> > was - quite fun to design and create.
> >       But when I program in Django, since I just have to work on user
> > responses - everything else being taken care of by Django - only, the
> > complete coding has become procedure oriented. It is not kludgy or
> > anything, but it doesnt have the nice feeling that we get when we code
> > a proper object oriented program.
>
> So you may want to learn to enjoy the nice feeling we get when we code a
> proper procedural program - or a proper functional one FWIW !-)
>
> There's nothing inherently wrong with procedural programming. Nor with a
> mix of procedural, OO and functional code - which is usually the case in
> Python. It's just a matter of using the right tool for the problem to
> solve.
>
> >       Is my coding in error here?
>
> Don't know - I don't have access to your code. But my experience with
> Django is that I tend to have quite a lot of code in models and
> templatetags, and much less in the views themselves. So I wouldn't say
> that "Django takes care of everything else". If you really ends up
> writing pages upon pages of repeting procedural code in your views and
> nothing in the other parts of the app, then yes, there might be
> something wrong - probably a case of AnemicDomainModel, and possibly a
> lack of knowledge of the whole framework. One of the reasons views are
> usually implemented as functions is that in most cases, you shouldn't
> have a need for more. FWIW, you sometimes don't even need to write a
> specific view - Django's GenericViews can handle quite a lot of cases
>
> Note also that Django doesn't _require_ that you use functions as view
> handlers - any callable object will do. But given how the HTTP protocol
> works and how Django is designed, there's more often than not just no
> *need* for a custom callable object.
>
> And finally, as Steve already mentioned, OO is first about objects, and
> that's what you're dealing with in your views - request objects, session
> objects, model objects etc...
>
> > This is infact my first web program,
> > so it might be the reason. What does other people find? Does web
> > server programming using web frameworks (Django, TurboGears etc) make
> > it procedure oriented?
>
> Not necessarily, no. Some frameworks requires your request handlers to
> be methods of classes FWIW, and nothing in Django prevents you from
> doing so if you want.
>
> > If I am in the wrong, it might be due to a
> > wrong design or mindset, and I would like to change it.

Hi Bruno,
   After reading your email, I tried reworking my code so that most of
my logic moves to Models.
   But, most probably because this is my first application
development, I am unable to do so.
   For example:
I have Models A,B, C, D . Now, there is not much model specific
code (preprocessing before updating code inside Models)in it. Rather
most of the code is of the format:
 data received and to be added to D. But for adding to D, check
whether it is already in C - if not add to C and B. etc...
   Now, I tried putting this code inside Model D,but it does not seem
to belong there - since it modifies other Models.

   Is keeping such code inside views against Django's/Application-
Developments philosophy? In that case, where will this go?

--
http://mail.python.org/mailman/listinfo/python-list


Re: how to find all completely connected sub-graphs?

2009-03-03 Thread Andre Engels
On Tue, Mar 3, 2009 at 7:35 AM, Hyunchul Kim  wrote:

> How can I find all "completely connected subgraphs" in a graph when node and
> edge data are available?
>
> "completely connected subgraph" is a group, all members of which are
> connected to each other.

Here is an algorithm I came up with in a few minutes of thinking,
complexity O(N*SN) with N being the number of nodes in the graph and
SN the sum of the nodes in each connected subgraph (there may well be
faster algorithms, but then you'd probably have to ask someone who
either already knows it, or spends significantly more time on it than
I did) - in pseudocode, but translating pseudocode into Python is an
easy thing to do:

Let N be the nodes in the graph.
A = {emptyset}  # that is, a set containing only the empty set in
the beginning
foreach node k in N:
foreach set a in A:
if k is connected to each node in a:
add k+{a} to A   # in such a way that it's not included in
the loop for the current node k

The completely connected subgraphs are the subgraphs for which the set
of nodes in the subgraph is in A.


-- 
André Engels, andreeng...@gmail.com
--
http://mail.python.org/mailman/listinfo/python-list


<    1   2