Re: usage of file separator

2007-12-31 Thread Thomas Wittek
[EMAIL PROTECTED]:
 for x in imagefilenames:
  imgfile=folder+/+x
   newimgfilenamelist.append(imgfile)
 
 [..] how do i make it work on other os?

from os.path import join
#..
imgfile=join(folder, x)

-- 
Thomas Wittek
Web: http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]
GPG: 0xF534E231
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python web frameworks

2007-11-20 Thread Thomas Wittek
Jeff:
 I don't know much about the others.  Turbo gears uses Mochikit, which
 hasn't had a new stable release in some time.  I prefer jQuery myself.

You can use jQuery with TurboGears if you develop custom widgets (I do so).
No problem here.

-- 
Thomas Wittek
Web: http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]
GPG: 0xF534E231
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Python 3000 Question

2007-10-30 Thread Thomas Wittek
Bjoern Schliessmann:
 Is there any particular reason why it should be a method?
 
 [..]
 
 To make a long story short: Most methods do specific things with
 objects; but len is a common function to get a simple property of
 an object.

You said it. IMHO it really could be a *property*, say `object.len`.
It doesn't do something on the object, but rather gives some information
about its state.

-- 
Thomas Wittek
Web: http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]
GPG: 0xF534E231
-- 
http://mail.python.org/mailman/listinfo/python-list


Inheriting automatic attributes initializer considered harmful?

2007-10-17 Thread Thomas Wittek
Hi!

I'm relatively new to Python, so maybe there is an obvious answer to my
question, that I just didn't find, yet.

I've got quite some classes (from a data model mapped with SQL-Alchemy)
that can be instatiated using kwargs for the attribute values. Example:

  class User(object):
  def __init__(self, name=None):
  self.name = name

  u = User(name=user name)

Writing such constructors for all classes is very tedious.
So I subclass them from this base class to avoid writing these constructors:

  class AutoInitAttributes(object):
  def __init__(self, **kwargs):
  for k, v in kwargs.items():
  getattr(self, k) # assure that the attribute exits
  setattr(self, k, v)

Is there already a standard lib class doing (something like) this?
Or is it even harmful to do this?
Although I cannot see any problems with it, I feel very unsafe about
that, because I've not seen this (in the few lines from some tutorials)
before.

Regards
-- 
Thomas Wittek
Web: http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]
GPG: 0xF534E231
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inheriting automatic attributes initializer considered harmful?

2007-10-17 Thread Thomas Wittek
Andrew Durdin:
 Is there already a standard lib class doing (something like) this?
 Or is it even harmful to do this?
 
 It depends on your kwargs and where they're coming from.

They should come from my own code.

 Does SQLAlchemy let you get a list of column names?

Generellay, it does.
But it also generates some additional attributes dynamically that are
not directly defined as columns.
So, restricting the attributes to the columns would be too strict.

Thanks!
-- 
Thomas Wittek
Web: http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]
GPG: 0xF534E231
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Automatically organize module imports

2007-10-16 Thread Thomas Wittek
Jean-Paul Calderone:
 On Mon, 15 Oct 2007 20:52:11 +0200, Thomas Wittek
 [EMAIL PROTECTED] wrote:
 Is there a tool that can organize my import section?
 
 Pyflakes will tell you which imports aren't being used (among other
 things).  I don't know if an existing tool which will automatically
 rewrite your source, though.

As Python itself complains about missing imports Pyflakes + Python
should be a good team in cleaning up my imports.
I'll give it a try. Thank you!

-- 
Thomas Wittek
Web: http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]
GPG: 0xF534E231
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Automatically organize module imports

2007-10-16 Thread Thomas Wittek
Alexandre Badez:
 If you're using Eclipse + PyDev, I strongly recommend you to give a
 try to PyLint (http://www.logilab.org/857;).

Great. It has a warning about unused imports. Perfect.
(Though, it was a bit tricky to install as easy_install didn't get the
dependencies right on Win XP)

Thank you!
-- 
Thomas Wittek
Web: http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]
GPG: 0xF534E231
-- 
http://mail.python.org/mailman/listinfo/python-list


Automatically organize module imports

2007-10-15 Thread Thomas Wittek
Hi!

Is there any possibility/tool to automatically organize the imports at
the beginning of a module?

I don't mean automatic imports like autoimp does as I like seeing where
my objects/functions really come from.
For the same reason I don't like from foo import *.

The downside is that you have a rather verbose import section at the
beginning of your code.
That's very bad if you reorganize your code and some imports are not
needed anymore or new imports are needed.
In Eclipse/Java there is a nice feature that automatically organizes
your imports, meaning that it removes unneded imports and even adds
missing imports automatically.

Unfortunately, this PyDev doesn't have an equally powerful feature.
As of the current version it only sorts the imports alphabetically, what
isn't very useful.

So, is there anything I can do about my imports?
Is there a tool that can organize my import section?
Shall I fall back to ambiguous imports like *?
Shall I write out the module name for every class/function that I use
(quite unhandy)?

Thank you!
-- 
Thomas Wittek
Web: http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]
GPG: 0xF534E231
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Library for crawling forums

2007-10-11 Thread Thomas Wittek
BlueCrux:
 I'm trying to write a utility to crawl forums and strip posts to be
 gone through offline. Just the content, I don't need to get who posted
 or sigs or any identifying info.
 
 Can anyone suggest a library that is already geared toward this?

Maybe a combination of mechanize [1] and BeautifulSoup [2]?

[1] http://wwwsearch.sourceforge.net/mechanize/
[2] http://www.crummy.com/software/BeautifulSoup/
-- 
Thomas Wittek
Web: http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]
GPG: 0xF534E231
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Yet another comparison of Python Web Frameworks

2007-10-06 Thread Thomas Wittek
Michele Simionato:
 At work we are shopping for a Web framework, so I have been looking at
 the available options
 on the current market.

At least, you missed Turbo Gears :)
http://turbogears.org/
For me, it feels more integrated than Pylons.

-- 
Thomas Wittek
Web: http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]
GPG: 0xF534E231
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python Spider

2007-08-23 Thread Thomas Wittek
luca bertini schrieb:
 1) ask google a query

http://code.google.com/apis/
http://code.google.com/apis/ajaxsearch/
But you probably have to reverse engineer the JavaScript lib.

 2) parse the data

http://blog.hill-street.net/?p=7

-- 
Thomas Wittek
Web: http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]
GPG: 0xF534E231
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDE for Python

2007-08-21 Thread Thomas Wittek
Joel Andres Granados schrieb:
 I have tried various times to use an IDE for python put have always been
 disapointed.
 I haven't revisited the idea in about a year and was wondering what the
 python people
 use.

Did you try Eclipse + PyDev? I'm quite happy with that.

-- 
Thomas Wittek
Web: http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]
GPG: 0xF534E231
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: LRU cache?

2007-08-11 Thread Thomas Wittek
Paul Rubin schrieb:
 Anyone got a favorite LRU cache implementation?  I see a few in google
 but none look all that good.  I just want a dictionary indexed by
 strings, that remembers the last few thousand entries I put in it.

I don't know a module for that (although it might exist), but I could
imagine how to implement it.

Generally a LRU cache could be implemented as a (linked) list with a
max. size of N.
On usage of an object this object will be moved to the top of the list
(and removed from the old position).
If it's not yet stored in the cache, you (fetch it from the source and)
add it on top and remove the last one, if the list exceeds N entries.

So you need to do two things:
1) Maintain a list: Use a (linked) list.
2) Random access to that list: Use a dict (hash), that also has to be
updated on removal/addition of objects.

-- 
Thomas Wittek
Web: http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]
GPG: 0xF534E231
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Distributing python apps

2007-07-09 Thread Thomas Wittek
Robert Dailey schrieb:
 Ideally, I would like for someone to be able to use my tools without
 having to install Python.

What about http://www.py2exe.org/ ?

py2exe is a Python Distutils extension which converts Python scripts
into executable Windows programs, able to run without requiring a Python
installation.

-- 
Thomas Wittek
http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pretty Printing Like Tidy for HTML

2007-07-07 Thread Thomas Wittek
Daniel:
 On Sat, 07 Jul 2007 21:35:40 +0300, David [EMAIL PROTECTED]
 wrote:
 Is there a pretty printing utility for Python, something like Tidy for
 HTML?
 
 Why not just write python as it should be written?

Oh, you write all the code you use yourself?
It's relatively common that you have some legacy code (e.g. from
(ex-)colleages) that doesn't conform to your style preferences/your
companys coding guidelines.
In such a case those tools can be very helpful.

-- 
Thomas Wittek
http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Matrix Multiplication

2007-06-17 Thread Thomas Wittek
[EMAIL PROTECTED]:
 Is there any direct function for matrix multiplication in Python or
 any of its packages? or do we have to multiply element by element?

First hit on google for python matrix:
http://matpy.sourceforge.net/

-- 
Thomas Wittek
http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: for web application development

2007-06-14 Thread Thomas Wittek
james_027:
 My problem is looking for a web framework for python, that could
 provide a natural way of developing web app.

The three bigger Python web frameworks seem to be:

- Django: http://www.djangoproject.com/
- TurboGears: http://www.turbogears.org/
- Pylons: http://pylonshq.com/

I only tried them briefly.

Django has its own componentes for almost everything (templating, ORM,
routing) and feels thus very integrated and solid.

TurboGears tries to use independent components like Kid, SQLObject and
CherryPy, which you can easily change to you own favorites. So you have
more flexibility, but also a bit more complexity.

Pylons is similar to TurboGears as it also uses independent components,
that are by some people consideres more modern. By default it uses
SQLAlchemy for ORM and Routes for routing/dispatching.
It also incorporates the Python WSGI standard for web apps.
For me it felt least integrated of those frameworks but it may have the
biggest future potentials.

You may take a look at those comparisons:
http://jesusphreak.infogami.com/blog/vrp1
http://www.ibm.com/developerworks/linux/library/l-django/
http://www.ibm.com/developerworks/linux/library/l-turbogears/

 I am avoiding to learn
 template language as much as possible.

You will need a templating language to put out your HTML.
Of course that will not be a full programming language like PHP.

-- 
Thomas Wittek
http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: stealth screen scraping with python?

2007-05-12 Thread Thomas Wittek
[EMAIL PROTECTED] schrieb:
 I am screen scraping a large volume of data from Yahoo Finance each
 evening, and parsing with Beautiful Soup.
 
 I was wondering if anyone could give me some pointers on how to make
 it less obvious to Yahoo that this is what I am doing, as I fear that
 they probably monitor for this type of activity, and will soon ban my
 IP.

Use anonymizing proxies:
http://www.google.com/search?q=proxies+OR+proxy+anonymous+OR+anonymizing

-- 
Thomas Wittek
http://gedankenkonstrukt.de/
Jabber: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list