Python 3.1 simplejson install

2010-01-29 Thread dirknbr
I am trying to install simplejson on Python 3.1 on Windows. When I do
'python setup.py install' I get 'except DisutilsPlatformError, x:
SyntaxError' with a dash under the comma.

Any ideas?

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


Email in 2.6.4

2010-05-24 Thread dirknbr
I am trying to run

from email.mime.text import MIMEText

but I get an

ImportError: No module named mime.text

Since email was pre-installed how do I fix this?

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


Re: Email in 2.6.4

2010-05-24 Thread dirknbr
I have now easy_installled email and I still get errors.

It doesn't error on 'import email' but does on call to MimeText.

import email
msg = MIMEText('test')

NameError: name 'MIMEText' is not defined

What should I do?
-- 
http://mail.python.org/mailman/listinfo/python-list


deduping

2010-06-21 Thread dirknbr
Hi

I have 2 files (done and outf), and I want to chose unique elements
from the 2nd column in outf which are not in done. This code works but
is not efficient, can you think of a quicker way? The a=1 is just a
redundant task obviously, I put it this way around because I think
'in' is quicker than 'not in' - is that true?

done_={}
for line in done:
done_[line.strip()]=0

print len(done_)

universe={}
for line in outf:
if line.split(',')[1].strip() in universe.keys():
a=1
else:
if line.split(',')[1].strip() in done_.keys():
a=1
else:
universe[line.split(',')[1].strip()]=0

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


compile as exe with arguments

2010-06-28 Thread dirknbr
I want to compile as an exe using py2exe but the function should take
arguments. How would I do this? Currently my exe runs (no errors) but
nothing happens.

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


Re: compile as exe with arguments

2010-06-28 Thread dirknbr
On Jun 28, 11:26 am, "Martin P. Hellwig" 
wrote:
> On 06/28/10 11:18, dirknbr wrote:
>
> > I want to compile as an exe using py2exe but the function should take
> > arguments. How would I do this? Currently my exe runs (no errors) but
> > nothing happens.
>
> I am not sure if I understand your question correctly, have you used a
> module like optparse and it doesn't do anything? It works for me the
> last time I used it.
>
> --
> mph

Aha that might be it, I had a look at 
http://docs.python.org/library/optparse.html
How do you integrate (options, args) = parser.parse_args()
with our function?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: compile as exe with arguments

2010-06-28 Thread dirknbr
On Jun 28, 11:40 am, dirknbr  wrote:
> On Jun 28, 11:26 am, "Martin P. Hellwig" 
> wrote:
>
> > On 06/28/10 11:18, dirknbr wrote:
>
> > > I want to compile as an exe using py2exe but the function should take
> > > arguments. How would I do this? Currently my exe runs (no errors) but
> > > nothing happens.
>
> > I am not sure if I understand your question correctly, have you used a
> > module like optparse and it doesn't do anything? It works for me the
> > last time I used it.
>
> > --
> > mph
>
> Aha that might be it, I had a look 
> athttp://docs.python.org/library/optparse.html
> How do you integrate (options, args) = parser.parse_args()
> with our function?

Ok I had a look at this now http://wiki.python.org/moin/OptParse and
got it.
-- 
http://mail.python.org/mailman/listinfo/python-list


optparse TypeError

2010-06-28 Thread dirknbr
I get an int object is not callable TypeError when I execute this. But
I don't understand why.

parser = optparse.OptionParser("usage: %lines [options] arg1")
parser.add_option("-l", "--lines", dest="lines",
  default=10, type="int",
  help="number of lines")
parser.add_option("-t", "--topbottom", dest="topbottom",
  default="T", type="str",
  help="T(op) or B(ottom)")

(options, args) = parser.parse_args()
if len(args) != 1:
parser.error("incorrect number of arguments")
lines=options.lines
tb=options.topbottom

Dirk
lines(args[0],topbottom=tb,maxi=lines)
-- 
http://mail.python.org/mailman/listinfo/python-list


Unicode error

2010-07-23 Thread dirknbr
I am having some problems with unicode from json.

This is the error I get

UnicodeEncodeError: 'ascii' codec can't encode character u'\x93' in
position 61: ordinal not in range(128)

I have kind of developped this but obviously it's not nice, any better
ideas?

try:
text=texts[i]
text=text.encode('latin-1')
text=text.encode('utf-8')
except:
text=' '

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


Re: Unicode error

2010-07-23 Thread dirknbr
To give a bit of context. I am using twython which is a wrapper for
the JSON API

 
search=twitter.searchTwitter(s,rpp=100,page=str(it),result_type='recent',lang='en')
for u in search[u'results']:
ids.append(u[u'id'])
texts.append(u[u'text'])

This is where texts comes from.

When I then want to write texts to a file I get the unicode error.

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


Urrlib2 IncompleteRead error

2010-07-27 Thread dirknbr
I am running urllib2.request and get this response when I do the read.
Any ideas what causes this?

return response.read()
  File "C:\Python26\lib\socket.py", line 329, in read
data = self._sock.recv(rbufsize)
  File "C:\Python26\lib\httplib.py", line 518, in read
return self._read_chunked(amt)
  File "C:\Python26\lib\httplib.py", line 561, in _read_chunked
raise IncompleteRead(''.join(value))
IncompleteRead: IncompleteRead(3235 bytes read)

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