Wx broken?

2009-01-15 Thread tmallen
I've tried a few of the examples from http://wiki.wxpython.org/Getting%20Started
, but after "Hello World" (window) nothing works. I get the following
error message with the other examples:

Traceback (most recent call last):
  File "C:/Documents and Settings/MyUserName/Desktop/WxExample.py",
line 1, in 
import wx
  File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx
\__init__.py", line 45, in 
from wx._core import *
  File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py",
line 6, in 
new_instancemethod = new.instancemethod
AttributeError: 'module' object has no attribute 'instancemethod'

Here's a snippet that generates this error:
http://pastebin.com/m2b4f4f9c

For those familiar with wx here, is this a bug in the library, or
should I be providing "instancemethod" at some point? Seeing that it's
an unhandled exception, I do expect the former.

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


Re: Wx broken?

2009-01-15 Thread tmallen
On Jan 15, 10:46 am, tmallen  wrote:
> I've tried a few of the examples 
> fromhttp://wiki.wxpython.org/Getting%20Started
> , but after "Hello World" (window) nothing works. I get the following
> error message with the other examples:
>
> Traceback (most recent call last):
>   File "C:/Documents and Settings/MyUserName/Desktop/WxExample.py",
> line 1, in 
>     import wx
>   File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx
> \__init__.py", line 45, in 
>     from wx._core import *
>   File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py",
> line 6, in 
>     new_instancemethod = new.instancemethod
> AttributeError: 'module' object has no attribute 'instancemethod'
>
> Here's a snippet that generates this error:http://pastebin.com/m2b4f4f9c
>
> For those familiar with wx here, is this a bug in the library, or
> should I be providing "instancemethod" at some point? Seeing that it's
> an unhandled exception, I do expect the former.
>
> Thanks,
> Thomas

Looking a little closer, this is what's causing the bug:

Wx: _core.py, lines 1-6:

# This file was created automatically by SWIG 1.3.29.
# Don't modify this file, modify the SWIG interface instead.

import _core_
import new
new_instancemethod = new.instancemethod

On this Win32 box, the "new" module doesn't have the "instancemethod"
attribute. What is new.instancemethod used for? "new_instancemethod,"
which should be assigned to the attr, does not show up again in this
particular source file.

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


Re: Wx broken?

2009-01-15 Thread tmallen
On Jan 15, 10:56 am, Mark Smith  wrote:
> >   File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py",
> > line 6, in 
> >     new_instancemethod = new.instancemethod
> > AttributeError: 'module' object has no attribute 'instancemethod'
>
> I'm guessing you either have a python file called 'new.py' in your
> working directory, or you have one in your pythonpath.
>
> --Mark

That's correct. Thanks!

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


UnicodeError for join()

2009-01-15 Thread tmallen
This line of code is throwing a UnicodeError for a handful of the few
hundred files I'm processing:

rc_file.write("\n\n".join([self.title, "### BEGIN CONTENT ###",
self.content]))
.
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position
442: ordinal not in range()

What should I change to make this unicode-safe?

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


Re: UnicodeError for join()

2009-01-15 Thread tmallen
On Jan 15, 3:34 pm, "Martin v. Löwis"  wrote:
> > rc_file.write("\n\n".join([self.title, "### BEGIN CONTENT ###",
> > self.content]))
> > .
> > UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position
> > 442: ordinal not in range()
>
> > What should I change to make this unicode-safe?
>
> One of self.title and self.content is a Unicode string, the other is
> a byte string. You need to change them to have the same type (depending
> on whether you want to process them as Unicode or byte strings).
>
> HTH,
> Martin

How can I do that?

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


Re: UnicodeError for join()

2009-01-15 Thread tmallen
On Jan 15, 4:09 pm, "Martin v. Löwis"  wrote:
> >> One of self.title and self.content is a Unicode string, the other is
> >> a byte string. You need to change them to have the same type (depending
> >> on whether you want to process them as Unicode or byte strings).
>
> > How can I do that?
>
> First, you need to find out what the respective types are:
>
> print type(self.title), type(self.content), repr(self.title),
> repr(self.content)
>
> With that information, as a very important next step, you need to
> understand why the error occurs.
>
> Then, you need to fix it, e.g. by converting all strings to byte
> strings.
> Suppose title is a unicode string, and further suppose the output
> is to be encoded in cp1252, then you change the line to
>
> rc_file.write(u"\n\n".join([self.title.encode("cp1252"),
>                             "### BEGIN CONTENT ###",
>                             self.content]))
>
> Regards,
> Martin

Thanks, it was the title that was causing problems. I just added the
encode() part to the self.title assignment.

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


mod_python resources

2008-12-16 Thread tmallen
I'm trying again because I'm stubborn. Maybe the fourth time will be
the charm...

Are there any good tutorials out there for setting up Apache with
mod_python?

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


Re: mod_python resources

2008-12-19 Thread tmallen
Here's my problem (it's a conceptual one). Coming from the world of
mod_php, each file can represent a page with no intervention. I was
not able to achieve the same with mod_python when I tried, and for
that matter, couldn't put the pieces together in a usable way.

Let me start simply: If I wanted to create a trivial site, (Home,
About, Contact) with a header and footer included, in PHP, it would be
done as such: each page (index.php, about.php, contact.php) includes
the template bits (header.php, footer.php). Is this simplicity
achievable using Python? And by "simplicity," I'm referring to
simplicity in execution; not necessarily an identical approach.

Thanks,
Thomas

On Dec 17, 4:25 am, Graham Dumpleton 
wrote:
> On Dec 17, 11:10 am, Дамјан Георгиевски  wrote:
>
> > > I'm trying again because I'm stubborn. Maybe the fourth time will be
> > > the charm...
>
> > > Are there any good tutorials out there for setting up Apache with
> > > mod_python?
>
> > mod_python is depreceated, nobody uses it. 
> > usemod_wsgihttp://www.modwsgi.org/
>
> The mod_python package is not deprecated, although it could be said to
> be sleeping at the moment. You'll also probably still find that more
> new people choose mod_python over mod_wsgi. This is because it has the
> more obvious name to look for when Googling. It also has publisher and
> PSP high level handler which are still attractive to many as they are
> more lightweight and easier to get into than the large WSGI
> frameworks. Finally, the Django folks still recommend in their
> documentation to use mod_python.
>
> Anyway, if wanting to host a WSGI capable application, using mod_wsgi
> would be the more obvious choice. If wanting to write your own
> framework, or work at low level, basing it on WSGI rather than
> mod_python specific APIs would certainly be a better long term
> direction to take.
>
> Graham

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


Is there a better/simpler way to filter blank lines?

2008-11-04 Thread tmallen
I'm parsing some text files, and I want to strip blank lines in the
process. Is there a simpler way to do this than what I have here?

lines = filter(lambda line: len(line.strip()) > 0, lines)

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


Re: Is there a better/simpler way to filter blank lines?

2008-11-04 Thread tmallen
On Nov 4, 4:30 pm, [EMAIL PROTECTED] wrote:
> tmallen:
>
> > I'm parsing some text files, and I want to strip blank lines in the
> > process. Is there a simpler way to do this than what I have here?
> > lines = filter(lambda line: len(line.strip()) > 0, lines)
>
> xlines = (line for line in open(filename) if line.strip())
>
> Bye,
> bearophile

I must be missing something:

>>> xlines = (line for line in open("new.data") if line.strip())
>>> xlines

>>> xlines.sort()
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'generator' object has no attribute 'sort'

What do you think?

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


Re: Is there a better/simpler way to filter blank lines?

2008-11-04 Thread tmallen
Between this info and 
http://www.python.org/doc/2.5.2/tut/node11.html#SECTION0011100
, I'm starting to understand how I'll use generators (I've seen them
mentioned before, but never used them knowingly).

> list_o_lines = [line for line in open(filename) if line.strip()]

+1 for "list_o_lines"

Thanks for the help!
Thomas

On Nov 4, 6:36 pm, Falcolas <[EMAIL PROTECTED]> wrote:
> On Nov 4, 3:30 pm, tmallen <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Nov 4, 4:30 pm, [EMAIL PROTECTED] wrote:
>
> > > tmallen:
>
> > > > I'm parsing some text files, and I want to strip blank lines in the
> > > > process. Is there a simpler way to do this than what I have here?
> > > > lines = filter(lambda line: len(line.strip()) > 0, lines)
>
> > > xlines = (line for line in open(filename) if line.strip())
>
> > > Bye,
> > > bearophile
>
> > I must be missing something:
>
> > >>> xlines = (line for line in open("new.data") if line.strip())
> > >>> xlines
>
> > >>> xlines.sort()
>
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > AttributeError: 'generator' object has no attribute 'sort'
>
> > What do you think?
>
> > Thomas
>
> Using the surrounding parentheses creates a generator object, whereas
> using square brackets would create a list. So, if you want to run list
> operations on the resulting object, you'll want to use the list
> comprehension instead.
>
> i.e.
>
> list_o_lines = [line for line in open(filename) if line.strip()]
>
> Downside is the increased memory usage and processing time as you dump
> the entire file into memory, whereas if you plan to do a "for line in
> xlines:" operation, it would be faster to use the generator.

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


Re: Is there a better/simpler way to filter blank lines?

2008-11-05 Thread tmallen
Why do I feel like the coding style in Lutz' "Programming Python" is
very far from idiomatic Python? The content feels dated, and I find
that most answers that I get for Python questions use a different
style from the sort of code I see in this book.

Thomas

On Nov 5, 7:15 am, Jorgen Grahn <[EMAIL PROTECTED]> wrote:
> On Tue, 04 Nov 2008 15:36:23 -0600, Larry Bates <[EMAIL PROTECTED]> wrote:
> > [EMAIL PROTECTED] wrote:
> >> tmallen:
> >>> I'm parsing some text files, and I want to strip blank lines in the
> >>> process. Is there a simpler way to do this than what I have here?
> >>> lines = filter(lambda line: len(line.strip()) > 0, lines)
>
> ...
>
> > Of if you want to filter/loop at the same time, or if you don't want all the
> > lines in memory at the same time:
>
> Or if you want to support potentially infinite input streams, such as
> a pipe or socket.  There are many reasons this is my preferred way of
> going through a text file.
>
> > fp = open(filename, 'r')
> > for line in fp:
> >      if not line.strip():
> >          continue
>
> >      #
> >      # Do something with the non-blank like:
> >      #
>
> > fp.close()
>
> Often, you want to at least rstrip() all lines anyway,
> for other reasons, and then the extra cost is even less:
>
>        line = line.rstrip()
>        if not line: continue
>        # do something with the rstripped, nonblank lines
>
> /Jorgen
>
> --
>   // Jorgen Grahn  \X/     snipabacken.se>          R'lyeh wgah'nagl fhtagn!

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


New variable?

2008-06-03 Thread tmallen
What's the proper way to instantiate a new variable? x = ""?
--
http://mail.python.org/mailman/listinfo/python-list


Picking apart strings

2008-06-03 Thread tmallen
Is there a way to pick apart this text without resorting to regular
expressions?

p {
color: black;
}

p -> element
color -> property
black -> value
--
http://mail.python.org/mailman/listinfo/python-list


Re: New variable?

2008-06-03 Thread tmallen
On Jun 3, 3:03 pm, Chris <[EMAIL PROTECTED]> wrote:
> On Jun 3, 8:40 pm, tmallen <[EMAIL PROTECTED]> wrote:
>
> > What's the proper way to instantiate a new variable? x = ""?
>
> You don't need to pre-declare your variables.  Just assign them as you
> need them and they will take the correct type.

unless I'm using the += or a similar operator, right? That doesn't
seem to instantiate a variable.
--
http://mail.python.org/mailman/listinfo/python-list


Hide raw_input text?

2008-08-13 Thread tmallen
I'm working on a little FTP project to get comfortable with ftplib.
It's all terminal-based right now, and one issue I'm having is hiding
password input text. I'd like one of two things to happen with this:
Either don't show any characters while I'm typing (like $ su), or
better, a '*' for every character. Is there a way to do this? I'm
planning on building this into a GUI tool using Tkinter or wxPython,
so methods using a secret input for those might be helpful as well ( I
could jump straight into the GUI part).

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


An FTP Client...My first real program!

2008-08-13 Thread tmallen
Here's the code:
http://pastebin.com/m21dfcc19

What could be improved? The script feels clumsy, and I have no
experience refactoring Python code. This will eventually be a GUI FTP
client. I'm mainly looking for design advice...
--
http://mail.python.org/mailman/listinfo/python-list


Re: An FTP Client...My first real program!

2008-08-13 Thread tmallen
On Aug 13, 3:27 pm, tmallen <[EMAIL PROTECTED]> wrote:
> Here's the code:http://pastebin.com/m21dfcc19
>
> What could be improved? The script feels clumsy, and I have no
> experience refactoring Python code. This will eventually be a GUI FTP
> client. I'm mainly looking for design advice...

Note that all it does right now is store account info and connect to
the host, listing the contents of the pwd. Anonymous connections work,
and the script is functionally sound.
--
http://mail.python.org/mailman/listinfo/python-list


Re: An FTP Client...My first real program!

2008-08-14 Thread tmallen
On Aug 13, 11:53 pm, "Python Nutter" <[EMAIL PROTECTED]> wrote:
> sorry cut off due to original email being sent not to the list due to gmail:
>
> A second for that suggestion--the ftp module in the python standard library is
> very low level and not very useful for beginners as a lot of the heavy
> lifting and management is still left up to you, the programmer.
>
> 2008/8/14 Python Nutter <[EMAIL PROTECTED]>:
>
> > ery low level and not very useful for beginners as a lot of the heavy
> > lifting and management is still left up to you, the programmer.
>
> > The module ftputil is a high-level interface to the ftplib module. The
> > FTPHost objects generated from it allow many operations similar to
> > those of os and os.path. An example:
>
> > # download some files from the login directory
> > host = ftputil.FTPHost('ftp.domain.com', 'user', 'secret')
> > names = host.listdir(host.curdir)
> > for name in names:
> >   if host.path.isfile(name):
> >       host.download(name, name, 'b')  # remote, local, binary mode
> > # make a new directory and copy a remote file into it
> > host.mkdir('newdir')
> > source = host.file('index.html', 'r')  # file-like object
> > target = host.file('newdir/index.html', 'w')  # file-like object
> > host.copyfileobj(source, target)  # similar to shutil.copyfileobj
> > source.close()
> > target.close()
>
> > Now if you are again purely in it for a challenge or for and
> > educational roller coaster ride, ignore the suggestion to look at
> > higher level ftp modules =)
>
> > Cheers,
> > PN
>
>

What work, specifically, am I duplicating? I have my eyes on a larger
application, so if this part can easily be taken care of, I'm all ears.
--
http://mail.python.org/mailman/listinfo/python-list


Re: An FTP Client...My first real program!

2008-08-14 Thread tmallen
On Aug 14, 9:54 am, tmallen <[EMAIL PROTECTED]> wrote:
> On Aug 13, 11:53 pm, "Python Nutter" <[EMAIL PROTECTED]> wrote:
>
>
>
> > sorry cut off due to original email being sent not to the list due to gmail:
>
> > A second for that suggestion--the ftp module in the python standard library 
> > is
> > very low level and not very useful for beginners as a lot of the heavy
> > lifting and management is still left up to you, the programmer.
>
> > 2008/8/14 Python Nutter <[EMAIL PROTECTED]>:
>
> > > ery low level and not very useful for beginners as a lot of the heavy
> > > lifting and management is still left up to you, the programmer.
>
> > > The module ftputil is a high-level interface to the ftplib module. The
> > > FTPHost objects generated from it allow many operations similar to
> > > those of os and os.path. An example:
>
> > > # download some files from the login directory
> > > host = ftputil.FTPHost('ftp.domain.com', 'user', 'secret')
> > > names = host.listdir(host.curdir)
> > > for name in names:
> > >   if host.path.isfile(name):
> > >       host.download(name, name, 'b')  # remote, local, binary mode
> > > # make a new directory and copy a remote file into it
> > > host.mkdir('newdir')
> > > source = host.file('index.html', 'r')  # file-like object
> > > target = host.file('newdir/index.html', 'w')  # file-like object
> > > host.copyfileobj(source, target)  # similar to shutil.copyfileobj
> > > source.close()
> > > target.close()
>
> > > Now if you are again purely in it for a challenge or for and
> > > educational roller coaster ride, ignore the suggestion to look at
> > > higher level ftp modules =)
>
> > > Cheers,
> > > PN
>
> What work, specifically, am I duplicating? I have my eyes on a larger
> application, so if this part can easily be taken care of, I'm all ears.

I see that there's this ftputil module. Are there any modules already
written for other clients, e.g. CVS, Subversion, Git, etc?
--
http://mail.python.org/mailman/listinfo/python-list