Re: ANN: geany-pyflakes 1.0

2011-08-05 Thread Filip Gruszczyński
> OK - it no longer crashes, but it doesn't appear to do anything.  Is there
> something further I need to do to configure it?  The Pyflakes tab does
> appear in the message window and I've created a new testpyflakes.py with
> code similar to your example.

OK, so there must be something wrong. Do you have pyflakes installed?
Where are they installed?

> Also, just FYI, the plugin manager now shows the version as 1.0.1 while the
> tar file name indicates 1.0.2.

Yeah, I should make a configure file with version and use it in c
code, to never make that mistake again, but I really, really don't
wanto to touch autotools again.

-- 
Filip Gruszczyński
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: geany-pyflakes 1.0

2011-08-05 Thread Filip Gruszczyński
> fyi - the downloaded geany-pyflakes-1.0.tar.gz is in fact not gzipped and
> should either be gizzped or simply named geany-pyflakes-1.0.tar.
>
> However, after activating the plugin, asking geany for a new file breaks
> geany and it rudely closes so I'm unable to actually do anything with it.

I have posted a gzipped version with a fix. Would you care to take a look?

-- 
Filip Gruszczyński
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: geany-pyflakes 1.0

2011-08-05 Thread Filip Gruszczyński
Hello everyone,

I have just published a small plugin for Geany IDE that adds Pyflakes
error detection to the editor. If there are people using Geany for
Python development I would be very grateful for opinions and
suggestions.

The plugin can be found here: http://code.google.com/p/geany-pyflakes/

-- 
Filip Gruszczyński
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: fathom 0.4.0, fathom-tools 0.1.0, qfathom 0.1.0

2011-06-16 Thread Filip Gruszczyński
Hello everyone!

I would like to announce new version of fathom as well as two more
packages built on top fathom. All this code is still very young and
experimental, so it is not supposed to be production ready. However, I
would greatly appreciate any advice or ideas on what could be useful
and what would you expect of those packages.

fathom 0.4.0
Fathom is python 3 library for inspecting database schema. It produces
objective model of all database objects and thus allows easy database
inspection.
Changes:
* Indices are top level objects and provide information about index uniqueness
* Procedure objects provide information about arguments for MySQL
* Rather than raise database specific exception library strives to
raise FathomError

http://code.google.com/p/fathom/

fathom-tools
This is a separate package with utilities that were earlier in fathom
package. It includes:
* fathom2django which produces django models from database schema and
now handles many to many fields, which makes it better than Django's
inspectdb
* fathom2graphviz which produces graphviz dot files with
entity-relationship diagrams
* utilities for building new tools based on fathom library

http://code.google.com/p/fathom-tools

qfathom
QFathom is graphical tool written in python3 and PyQt for inspecting
the database. It is basically a graphical frontend for fathom.

http://code.google.com/p/qfathom/

And once again any kind of ideas or comments would be greatly appreciated.


-- 
Filip Gruszczyński
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Fathom 0.3.0

2011-05-15 Thread Filip Gruszczyński
Hi,

I have released version 0.2.0 of fathom, python3 package for database
inspection. Fathom supports retrieving database schema from Sqlite3,
PostgreSQL, MySQL and Oracle.

This is still very early version and I am experimenting with different
approaches. As always I would be very thankful for any input and suggestions
about what would be useful in the library or tools.

Here you can download the package:
http://code.google.com/p/fathom/downloads/list

**Changes in 0.3.0:**
-> Oracle support :-)
-> Triggers provide information about event upon which they are fired
-> utility function for finding procedures that access a table
-> fathom2graphviz draws lines between columns for foreign key
-> fathom2graphviz and fathom2django can now print output to a file,
rather than to std

-- 
Filip Gruszczyński
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: fathom 0.2.0

2011-04-09 Thread Filip Gruszczyński
Hi,

I have released version 0.2.0 of fathom, python3 package for database
inspection. Fathom supports retrieving database schema from Sqlite3,
PostgreSQL and MySQL.

This is still very early version and I am experimenting with different
approaches. I would be very thankful for any input and suggestions
about what would be useful in the library or tools.

**Changes in Version 0.2.0**

* get_database convenience function, that doesn't require knowledge of
database type
* Index object provides information about columns, that are indexed
* Table provides information about foreign keys
* Procedure objects provide return value and procedure's body
* Database object provides trigger list
* Utility function get_database_type, that tries to guess database type
* Tools:
  -> fathom2django that generates django models from database schema
  -> fathom2graphviz that generates entity-relationship diagrams in
graphviz dot language, that can be turned into pdf or image files

-- 
Filip Gruszczyński
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: fathom 0.2.0

2011-04-09 Thread Filip Gruszczyński
I forgot links:

Homepage: http://code.google.com/p/fathom/

Documentation: http://code.google.com/p/fathom/wiki/Manual

-- 
Filip Gruszczyński
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: fathom 0.1.0

2011-03-19 Thread Filip Gruszczyński
Hello everyone!

I have created a small python package for python3 called fathom that
provides database inspection. It is in a very early stage, rather a
proof of concept right now. It provides basic information about
database schema and works with Sqlite3, PostgreSQL and MySQL. I am
looking for comments and additional ideas for new features..

Documentation can be found here: http://code.google.com/p/fathom/wiki/Manual

Package can be downloaded from PyPi or from here:
http://code.google.com/p/fathom/downloads/list

-- 
Filip Gruszczyński
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: function annotations in open source projects

2011-03-16 Thread Filip Gruszczyński
Thanks for the links.

-- 
Filip Gruszczyński
-- 
http://mail.python.org/mailman/listinfo/python-list


function annotations in open source projects

2011-03-14 Thread Filip Gruszczyński
Do you know any open source python3 projects that use function
annotations? I would like to see some real use, so maybe I find them
useful to use in my own project.

-- 
Filip Gruszczyński
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: logbuilder 0.1.0a

2009-12-21 Thread Filip Gruszczyński
This is a one-time post to annouce the creation of logbuilder project,
an open source tool for change log creation based on version control
commit messages. Using conventions in commit messages logbuilder
detects messages that can be imported into the change log and
painlessly creates on for every version of software.

Home page: http://code.google.com/p/logbuilder/

Features:
* Subersion support
* Mercurial support
* Filtering using wildcards, regular expressions and string matching
* (planned) Using templates for displaying results

Requirements:
* Python 2.6+
* pysvn or mercurial

For more information, please come to http://code.google.com/p/logbuilder/.

-- 
Filip Gruszczyński
-- 
http://mail.python.org/mailman/listinfo/python-list


Which is more pythonic?

2009-12-03 Thread Filip Gruszczyński
I have just written a very small snippet of code and started thinking,
which version would be more pythonic. Basically, I am adding a list of
string to combo box in qt. So, the most obvious way is:

for choice in self.__choices:
choicesBox.addItem(choice)

But I could also do:

map(self.__choices, choicesBox.addItem)

or

[choicesBox.addItem(choice) for choice in self.__choices]

I guess map version would be fastest and explicit for is the slowest
version. However, the first, most obvious way seems most clear to me
and I don't have to care about speed with adding elements to combo
box. Still, it's two lines instead of one, so maybe it's not the best.
So, which one is?

-- 
Filip Gruszczyński
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Validating positional arguments in optparse

2009-10-23 Thread Filip Gruszczyński
> That being said, I still stick with optparse. I prefer the dogmatic
> interface that makes all my exe use the exact same (POSIX) convention. I
> really don't care about writing /file instead of --file

I would like to keep POSIX convention too, but just wanted
OptionParser to do the dirty work of checking that arguments are all
right for me and wanted to know the reason, it doesn't.

I guess I should write a subclass, which would do just that.


-- 
Filip Gruszczyński
-- 
http://mail.python.org/mailman/listinfo/python-list


Validating positional arguments in optparse

2009-10-23 Thread Filip Gruszczyński
optparse module is quite smart, when it comes to validating options,
like assuring, that certain option must be an integer. However, I
can't find any information about validating, that positional arguments
were provided and I can't find methods, that would allow defining
positional argument in OptionParser. Is it possible to do this, or was
it intentionaly left this way?

-- 
Filip Gruszczyński
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Specific iterator in one line

2009-06-30 Thread Filip Gruszczyński
Oh, and there is additional requirement: it must be a one liner with
at most 80 characters ;-)

W dniu 30 czerwca 2009 10:44 użytkownik Filip Gruszczyński
 napisał:
> This is purely sport question. I don't really intend to use the answer
> in my code, but I am wondering, if such a feat could be done.
>
> I have a following problem: I have a list based upon which I would
> like to construct a different one. I could simply use list
> comprehensions, but there is an additional trick: for some elements on
> this list, I would like to return two objects. For example I have a
> list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I
> would like to add 2 'b', like this:
>
> [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b']
>
> The easy way is to return a tuple ('b', 'b') for 1s and then flatten
> them. But this doesn't seem very right - I'd prefer to create a nice
> iterable right away. Is it possible to achieve this? Curiosly, the
> other way round is pretty simple to achieve, because you can filter
> objects using if in list comprehension.
>
>
> --
> Filip Gruszczyński
>



-- 
Filip Gruszczyński
-- 
http://mail.python.org/mailman/listinfo/python-list


Specific iterator in one line

2009-06-30 Thread Filip Gruszczyński
This is purely sport question. I don't really intend to use the answer
in my code, but I am wondering, if such a feat could be done.

I have a following problem: I have a list based upon which I would
like to construct a different one. I could simply use list
comprehensions, but there is an additional trick: for some elements on
this list, I would like to return two objects. For example I have a
list of 0s and 1s and for 0 I would like to add 1 'a' and for 1 I
would like to add 2 'b', like this:

[1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b']

The easy way is to return a tuple ('b', 'b') for 1s and then flatten
them. But this doesn't seem very right - I'd prefer to create a nice
iterable right away. Is it possible to achieve this? Curiosly, the
other way round is pretty simple to achieve, because you can filter
objects using if in list comprehension.


-- 
Filip Gruszczyński
-- 
http://mail.python.org/mailman/listinfo/python-list


urllib2 urlopen takes too much time

2009-06-21 Thread Filip Gruszczyński
I have encountered a performance problem using suds, which was traced
down to _socket.recv. I am calling some web services and each of them
uses about 0.2 sec and 99% of this time is spent on urllib2.urlopen,
while the rest of the call is finished in milliseconds. Because of
this, my web app works really slow, especially when it must do many ws
calls. I could of course decrease the number of calls and do a lot of
caching (which would be quite perilous and I wouldn't like to delve
into this), but it seems as treating symptoms, rather than the illness
itself.

The machine I am connecting to through ws is in the same building, the
connection should be really fast and mostly it is - except for using
suds. Is it possible, that I could done something wrong and it hangs
on this socket for too long? Have anyone encountered similar problems?
Oh, and we did some profiling using also other tool written in C#,
that also uses those web services and it worked much faster, so it
doesn't seem to be connection problem.

-- 
Filip Gruszczyński
-- 
http://mail.python.org/mailman/listinfo/python-list


ECG segmentation

2009-05-08 Thread Filip Gruszczyński
Hi!

I need to create a script, that performs ECG segmentation, but I can
hardly find any useful materials on the web. Did anyone try to do this
and could point me to some good materials/snippets about this?

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Re: Pythonic emptiness checking

2009-04-29 Thread Filip Gruszczyński
Yes, I get the difference. If x is [], than

if x:

won't be executed and

if x is not None:

will be.

Thanks for clarifying.

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Pythonic emptiness checking

2009-04-29 Thread Filip Gruszczyński
One of the Python Zen rules is Explicit is better implicit. And yet
it's ok to do:

if x:
   do_sth

when x is string or list. Since it's very comfy, I've got nothing
against though. I am just curious, why is it so?

And one more thing: is it ok to do

if x:

instead of

if x is not None:

Because I often encounter it and would like to know, if I can simplify
it. Especially that I liked similar construction in C/C++.

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Re: Too early implementation

2009-04-18 Thread Filip Gruszczyński
Yep, I have heard a lot about test driven development. I am now
programming a lot using DJango and I would like to use its test
framework to try it. However, I have little experience with this (as
most people I know). I also have no idea, how to apply this, when I
write code heavily focused on user interface.

I thought, that prototyping is cool, especially with python, where you
can create something functional pretty quickly. But recently I was met
with a situation, when after writing 1k lines of prototype and then
writing main program > 3k lines I noticed, that there is something
really wrong with the design. It was then, that I started wondering:
maybe I should first prepare some good design documents, I don't know
some SAD or something.

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Too early implementation

2009-04-18 Thread Filip Gruszczyński
I am not a very disciplined person. Usually I rush to my next
assignment and code furiously, hoping that my initial understanding of
the stated problem will be just fine. And Python does very little to
stop me ;-) If I had to do something in C++, I know I would have to
write all those header files, fill stubs, etc., which is a lot of
work, which I don't want to do twice. So I take a while and start to
think, because it's better to be safe, than sorry.

With Python you rarely are sorry, because you can do everything so
quickly. And yet, at some point you see, that flaws in design get so
annoying, that you need to do something about them. Usually at that
point it's a bit problematic ;-)

So, do you know some good methods to prevent myself from just starting
coding (which I like very much) and do some thinking about the problem
(which I like a little less ;-))?

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Re: Script for a project inside own directory

2009-03-22 Thread Filip Gruszczyński
Works great. Thanks a lot.

2009/3/22 Maxim Khitrov :
> 2009/3/22 Filip Gruszczyński :
>> I am having a project built like this:
>>
>> project
>>   module1.py
>>   module2.py
>>   packages1/
>>     module3.py
>>
>> etc.
>>
>> I have script that uses objects from those modules/packages. If I keep
>> this script inside project directory it's ok and it works. But I would
>> like to move it to own scripts directory and from there it doesn't
>> work. I think I understand why it doesn't work (the root of local
>> packages and modules is there and it can't see what it above it), but
>> I would like to ask if there is any workaround? I would like to keep
>> all my scripts in separate dir instead of main dir. I like to keep it
>> clean.
>
> import sys
> sys.path.append('')
>
> If project directory is one level up, you can do something like this:
>
> import os
> import sys
> sys.path.append(os.path.realpath('..'))
>
> - Max
>



-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Script for a project inside own directory

2009-03-22 Thread Filip Gruszczyński
I am having a project built like this:

project
   module1.py
   module2.py
   packages1/
 module3.py

etc.

I have script that uses objects from those modules/packages. If I keep
this script inside project directory it's ok and it works. But I would
like to move it to own scripts directory and from there it doesn't
work. I think I understand why it doesn't work (the root of local
packages and modules is there and it can't see what it above it), but
I would like to ask if there is any workaround? I would like to keep
all my scripts in separate dir instead of main dir. I like to keep it
clean.

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Script in /usr/bin doesn't see my packages

2009-03-01 Thread Filip Gruszczyński
I have used distutils to install a python package and a script, that
runs a program. Everything seemed ok, when I run interpreter I can
import stuff, that I have just installed. But when I run script that
was installed into /usr/bin it can't import anything. This happens
also with my test scripts: i put an import statement there and run
them (they are outside of development directory) and they import stuff
just the way they should. But when I put them into /usr/bin they stop.
Could anyone help me on this?

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Re: Calling a class instance like a function

2009-02-18 Thread Filip Gruszczyński
__call__

2009/2/19 Uberman :
> I'm wondering if there's a way to invoke a "function" operator on a Python
> class instance.  For example, given a class instance:
>
>myClass = MyClass()
>
> I want to call that instance like a function, with an argument value:
>
>myClass(5.0)
>
> I can override the "()" operator in C++, so I'm wondering if there's a way to
> do it in Python as well.
>
> Thanks!
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tree views - Best design practices

2009-01-08 Thread Filip Gruszczyński
> Yes. There is a difference between the interface of an object (namely,
> what methods and attributes it has and what their semantic meaning is)
> and the class of an object (what methods and attributes it has and how
> they are implemented.)
>
> In general, you shouldn't be asking about an object's class. Down the
> road, you may want to use an object that isn't of the same class but
> does support the interface.
>
> Consider how the file object is used in Python. Pretty much every
> place you can use a file object you can use a StringIO, right? That's
> because StringIO supports the file interface while it isn't a file.
>
> You may want to read up on 'duck typing' to get a better sense of why
> this is important.

I have read also your next message and these are good arguments for
dynamically typed languages and really convinces me - I mean that they
provide some flexibility at the cost of writing a little more. They
provide flexibility though in a different field. Duck typing is great,
because it allows completely use of a completely different hierarchy,
which only has to have the same interface.

But I am looking for a different type of flexibility. I would like to
be able to add more classes to my hierarchy and not have to change my
code in many places when I add new class to the hierarchy. If I have
to change every class in the hierarchy because I add new class, then
it's not something I would like to do. And idea how I can avoid this?

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tree views - Best design practices

2009-01-08 Thread Filip Gruszczyński
>class Element(object):
>@staticmethod
>def is_leaf(): return True
>@staticmethod
>def is_branch(): return False
>
>class Group(object):
>@staticmethod
>def is_leaf(): return False
>@staticmethod
>def is_branch(): return True
>
> Of course, you have to give priority to one or the other, in case an
> object thinks it is both.
>
>if thing.is_branch():
># Treat it like a branch
>elif thing.is_leaf():
># Treat it like a leaf
>
> I believe this is a simpler method than checking a single attribute
> for a name.

Is it really any better than asking for class? I mean, if I need to
add another class to a hierarchy which behaves differently, will it be
more flexible (actually you have to add another method to every class
and check for in the gui). I believe it's just the same as asking for
the class, but we hide it under static methods. It's no different
though.

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tree views - Best design practices

2009-01-08 Thread Filip Gruszczyński
I'd love to have operations methods, which would return names of
operations and references to proper methods. The problem is that
certain operations require more, than just running some operation on
the Group or Element. Let's say, you want to add new group to an
existing one - you can't do that to an element. But adding a group
cannot be just done by calling group.addGroup. You must first
construct the group or at least get information require to construct a
group, so you must for example call a dialog which will ask for
information about the group. And that's in conflict with model/view
pattern.

And that's not all. I am using qt and when I want to add this group to
another one, I have to first call beginInsertRows on the model used by
the tree view (it's a layer between the gui and the real model).

I tried building a wrapper around my model which would provide
additional info, but then I had to keep relations between objects in
two places (relations between real groups and elements and wrapper
groups and wrapper elements), which wasn't the right way to do. I just
can figure a simple, elegant way to do this.

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tree views - Best design practices

2009-01-08 Thread Filip Gruszczyński
>>>> class Element(object):
>operations = "Element operations"
>
>
>>>> class Group(object):
>operations = "Group operations"
>
>
>>>> e = Element()
>>>> g = Group()
>>>>
>>>> e.operations
> 'Element operations'
>>>> g.operations
> 'Group operations'

But this is the same as asking for a class, except for having to write
a method giving some form of a class name and then basing on this
classname display operations. I know this solution, but this is what I
would like to evade.

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Tree views - Best design practices

2009-01-08 Thread Filip Gruszczyński
Hi!

I have certain design problem, which I cannot solve elegantly. Maybe
you know some good design patterns for this kind of tasks.

Task:

We have a model which has two kinds of objects: groups and elements.
Groups can hold other groups (subgroups) and elements. It's a simple
directory tree, for example. We would like to display it in a tree
view (which sound good for this kind of model). What is more required,
for groups and elements there are different sets of operations, which
should be available under right click. For example for group, there
should be operations: 'add element' and 'add group', and for element
there should be 'change properties'.

Do you know any smart way to achieve this? The simplest way is to ask
for the class and display operations accordingly. But from the first
day with OO programming I have heard, that asking for class is wrong.
But I can hardly see any easy and more maintainable solution for this
problem. Could you help me with this?

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Re: deleting a method

2009-01-04 Thread Filip Gruszczyński
> To answer the second question: since 'foo' is an attribute of the
> class 'A', you can delete the attribute from the class.
>
>>>> class A(object):
>... def foo(self):
>... pass
>...
>>>> a = A()
>>>> 'foo' in dir(a)
>True
>>>> del A.foo
>>>> 'foo' in dir(a)
>False

Thanks, now I see, what happens, but don't exactly know why. Could you
point me to some good explanation how object creation is performed in
Python? I browsed language reference and google, but couldn't find
good explanation.

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


deleting a method

2009-01-03 Thread Filip Gruszczyński
I am trying to delete a method from a class. It's easy to delete other
attributes, but when I try:

>>> class A:
... def foo():
... pass
...
>>> a = A()
>>> del a.foo

I get

Traceback (most recent call last):
  File "", line 1, in 
AttributeError: A instance has no attribute 'foo'

Why is it so and how may still delete it?

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Re: Removing None objects from a sequence

2008-12-13 Thread Filip Gruszczyński
Just to be clear, I decided to use generator by alex23, as it seems
simple, short and understandable. Still reading this thread was quite
interesting, thanks :-)

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Re: Removing None objects from a sequence

2008-12-12 Thread Filip Gruszczyński
I am not doing it, because I need it. I can as well use "if not elem
is None", but I just wanted to know, if there is some better way of
doing this. I like to know :-)

And I can't understand why you are becoming so aggressive because of
this. Just because I asked for that, doesn't mean, that I will put
some obfuscated code into my project. I just wanted to learn something
new - I checked itertools, I googled a bit, now I wanted to ask here
if someone knew some really cool way of this.  All the other
assumptions weren't really necessary.

Thanks for those ideas, however. I like the last one a lot :)

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Re: Removing None objects from a sequence

2008-12-12 Thread Filip Gruszczyński
I don't mean memory, but space in code ;-)

I'll try this generator :)

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Removing None objects from a sequence

2008-12-12 Thread Filip Gruszczyński
Hi!

I would like to iterate over a sequence nad ignore all None objects.
The most obvious way is explicitly checking if element is not None,
but it takes too much space. And I would like to get something faster.
I can use
[ sth for sth in self.__sth if not sth is None ], but I don't know if
that's the best way. I checked itertools, but the only thing that
seemed ok, was ifilter - this requires seperate function though, so
doesn't seem too short. How can I get it the shortest and fastest way?

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Re: Do more imported objects affect performance

2008-12-01 Thread Filip Gruszczyński
I see. Thanks for a really good explanation, I like to know, how to do
things in the proper way :)

2008/12/1 Nick Craig-Wood <[EMAIL PROTECTED]>:
> Rafe <[EMAIL PROTECTED]> wrote:
>>  On Dec 1, 7:26?am, "Filip Gruszczy?ski" <[EMAIL PROTECTED]> wrote:
>> > I have following question: if I use
>> >
>> > from module import *
>> >
>> > instead
>> >
>> > from module import Class
>> >
>> > am I affecting performance of my program? I believe, that all those
>> > names must be stored somewhere, when they are imported and then
>> > browsed when one of them is called. So am I putting a lot of "garbage"
>> > to this storage and make those searches longer?
>>
>>  Why use it if you don't need it? Your post implies a choice and the
>>  '*' import can really make things muddy if it isn't actually necessary
>>  (rare). Why not just import the module and use what you need? It is
>>  way easier to read/debug and maintains the name-space.
>
> Importing the module is actualy slower...  If you import the name into
> your namespace then there is only one lookup to do.  If you import the
> module there are two.
>
> $ python -m timeit -s 'from timeit import Timer' 'Timer'
> 1000 loops, best of 3: 0.0784 usec per loop
>
> $ python -m timeit -s 'import timeit' 'timeit.Timer'
> 100 loops, best of 3: 0.243 usec per loop
>
> I'm not suggestion you should ever use "from module import *" only
> ever import the things you actually need, eg
> "from module import MyClass, my_function"
>
> And here is the test again, actually calling something with the same
> difference in execution speed :-
>
> $ python -m timeit -s 'from os import nice' 'nice(0)'
> 100 loops, best of 3: 1.21 usec per loop
>
> $ python -m timeit -s 'import os' 'os.nice(0)'
> 100 loops, best of 3: 1.48 usec per loop
>
> --
> Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Re: pydoc enforcement.

2008-11-30 Thread Filip Gruszczyński
Hey!

If you are interested, I have written a small tool for declaring
variables and attributes. It's not very sophisticated, because I have
written it solely for own use. It might be useful though. You can
download it from you: http://code.google.com/p/pyver/downloads/list

For a small example, it works like this:

def foo():
a = 5

class Bar:

def __init__(self):
self.a = 5

Errors:
Line 2: Variable a in function foo was not specified;
Line 7: Field a in function __init__ was not specified;

To have it working fine, you have to declare fields and variables like this:

def foo():
#| a |
a = 5

class Bar:

#| a |

def __init__(self):
self.a = 5

But as soon as I finished I realized, I don't really need this since
there are pychecker and pylint that do all what I need and I don't
have to type all those declarations. But I have learned how to parse
python code using tools from stdlib, so it wasn't really wasted time.
Hope this helps :-) If you want to know something more about this,
don't hesitate to ask.

2008/12/1 [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
> I've been thinking about implementing (although no idea yet *HOW*) the
> following features/extension for the python compile stage and would be
> interested in any thoughts/comments/flames etc.
>
> Basically I'm interested adding a check to see if:
>  1) pydoc's are written for every function/method.
>  2) There are entries for each parameter, defined by some
> predetermined syntax.
>
> My idea is that as much as I love dynamic typing, there are times when
> using some modules/API's that have less than stellar documentation. I
> was thinking that if it was possible to enable some switch that
> basically forced compilation to fail if certain documentation criteria
> weren't met.
>
> Yes, it should be up to developers to provide documentation in the
> first place. Or, the client developer might need to read the source
> (IF its available)...  but having some "forced" documentation might at
> least ease the problem a little.
>
> For example (half borrowing from Javadoc).
>
> class Foo( object ):
>
>  def bar( self, ui ):
> pass
>
>
> Would fail, since the bar method has an "unknown" parameter called
> "ui".
> What I think could be interesting is that the compiler forces some
> documentation such as:
>
> class Foo( object ):
>
>  def bar( self, ui ):
>"""
>@Param: ui :  blah blah blah.
>"""
> pass
>
>
> The compiler could check for @Param matching each parameter passed to
> the method/function. Sure, a lot of people might just not put a
> description in, so we'd be no better off. But at least its getting
> them *that* far, maybe it would encourage them to actually fill in
> details.
>
> Now ofcourse, in statically  typed language, they might have the
> description as "Instance of UIClass" or something like that. For
> Python, maybe just a description of "Instance of abstract class UI" or
> "List of Dictionaries"...  or whatever. Sure, precise class names
> mightn't be mentioned (since we mightn't know what is being used
> then), but having *some* description would certainly be helpful (I
> feel).
>
> Even if no-one else is interested in this feature, I think it could
> help my own development (and would be an interested "first change"
> into Python itself).
>
> Apart from bagging the idea, does anyone have a suggestion on where in
> the Python source I would start for implementing such an idea?
>
> Thanks
>
> Ken
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Do more imported objects affect performance

2008-11-30 Thread Filip Gruszczyński
I have following question: if I use

from module import *

instead

from module import Class

am I affecting performance of my program? I believe, that all those
names must be stored somewhere, when they are imported and then
browsed when one of them is called. So am I putting a lot of "garbage"
to this storage and make those searches longer?

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Re: Project structure - Best practices

2008-11-30 Thread Filip Gruszczyński
> http://jcalderone.livejournal.com/39794.html

That's exactly what I have read before posting here ;-)

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Project structure - Best practices

2008-11-30 Thread Filip Gruszczyński
This is first time that I am building python application that is
larger than a single module and I would like to do it right. I google
it a bit, finding some stuff about not using src directory (which I
have seen so many times, that I believed it be standard) and using
packages. Still, there are few things, that I would like to achieve
with this structure:
* being able to use pychecker a lot - catching all typos in one shot
instead of running app many times really saves me a lot of time
* being able to write some unit tests
* having clean division of code among packages and modules (I have
seen some projects, where modules are pretty large - I would like to
keep them logically divided, event if they stay smaller)

My project is a tool for people interested in role playing games. My
current structure looks something like this:

/src
rpgDirectory.py (main script, running the app)

src/rpg
plans.py
support.py
gui.py
iosystem.py

src/rpg/character
model.py
sheet.py
gui.py
handlers.py
requirements.py

The problem is, that modules from src/rpg/character use classes
defined in support.py. Therefore I have to use absolute paths to
import it and this works only, when I run rpgDirectory.py. When I use
pychecker, it can't import this module and fails. Any suggestions, how
can I avoid this and what structure should I use?

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Re: Two instances share an attribute

2008-11-15 Thread Filip Gruszczyński
Every day something new. Thanks a lot :)

2008/11/15 Cameron Simpson <[EMAIL PROTECTED]>:
> On 15Nov2008 22:41, Filip Gruszczyński <[EMAIL PROTECTED]> wrote:
> | I really don't understand, what's happening with the following code.
> | Am I doing something wrong?
>
> Yes. This is a common mistake:
>
> | class EnumeratedContent:
> | def __init__(self, values = []):
> | self.values_ = values
>
> The "values = []" happens at class definition time, not instance
> definition time. So when "values" is not supplied, the same list
> is reused as the default value.
>
> The usual idiom is this:
>
>  class EnumeratedContent:
>  def __init__(self, values = None):
>  if values is None:
>  values = []
>  self.values_ = values
>
> which makes a new [] during the instance creation.
>
> Cheers,
> --
> Cameron Simpson <[EMAIL PROTECTED]> DoD#743
> http://www.cskk.ezoshosting.com/cs/
>
> If you don't live on the edge, you're taking up too much space. - t-shirt
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


Two instances share an attribute

2008-11-15 Thread Filip Gruszczyński
I really don't understand, what's happening with the following code.
Am I doing something wrong?

#!/usr/bin/python

class EnumeratedContent:

def __init__(self, values = []):
self.values_ = values

def values(self):
return self.values_

def addValue(self, value):
self.values_.append(value)

x = EnumeratedContent()
x.addValue('ff')
print x.values()
x = EnumeratedContent()
x.addValue('gg')
print x.values()

This code prints:

['ff']
['ff', 'gg']

Why the heck self.__values keeps old list? Can anyone explain it to me?

I am using:

Python 2.5.2 (r252:60911, Sep 14 2008, 23:49:00)
[GCC 4.1.2 (Gentoo 4.1.2 p1.0.2)] on linux2


-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list


XML validation in stdlib?

2008-06-14 Thread Filip Gruszczyński
Hi!

I took a look at the standard library and tried to find some
validation against schema tools, but found none. I googled, but found
only links to external libraries, that can do some validation. Does it
mean, that there is no validation in stdlib or have I just missed
something?

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list

Ideas for master's thesis

2008-06-02 Thread Filip Gruszczyński
Hello there,

I am student of CS at the University of Warsaw, currently 4th year. I
am attending Object Oriented Programming seminar and it is about time,
I started looking for an idea of my master's degree project. As I like
Python very much, I would like to do something with this language, yet
I don't know if there are any needs/science fields, that could be used
as a basis for a thesis. Therefore I would like to ask, if there is
any way to access any person involved in development, who would help
me find some field that need to be developed/researched (rather the
first one) and would be close enough to the OOP, so I could present it
to a mentor (he is cool with doing something for OSS community).

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list

Re: Explicit variable declaration

2008-04-25 Thread Filip Gruszczyński
>  In Python the standard patten for "declaring" variables is just to assign to
>  them as they are needed.  If you want the effect of a declaration as you
>  would do in C, you can just define the variable and initialize it to 0 or
>  None.  (Or {} for a new dictionary, or [] for a new list.)

Yep, I get it and I absolutely love this about Python. What I don't
actually love is situation, where I misspell and instead of setting
one variable, other is created. This is why I would like to declare
variables first and say, that these are the only ones, that can be set
in certain function (the same with fields in a class).

I am finishing a small tool, that allows to create such declarations
in similar manner to Smalltalk declarations. I hope I can post a link
to it soon.

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list

Re: Explicit variable declaration

2008-04-23 Thread Filip Gruszczyński
>  If you want to just declare that name exist, but doesn't want to
>  declare the type, why don't you just do this:
>
>  def somefunc():
> nonlocal = nonlocal
> local = 0 # or None or [] or an initial value
> #
> return nonlocal * local

Err.. I don't quite get. How it may help me? Could you explain?

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list

Re: Explicit variable declaration

2008-04-23 Thread Filip Gruszczyński
Wow! This is extremely easy and seems to do exactly what I need. Those
decorators are pretty powerful then. Thanks for your help, I'll try to
use this.

>  def uses(names):
> def decorator(f):
> used = set(f.func_code.co_varnames)
> declared = set(names.split())
> undeclared = used-declared
> unused = declared-used
> if undeclared:
> raise ValueError("%s: %s assigned but not declared"
>% (f.func_name, ','.join(undeclared)))
> if unused:
> raise ValueError("%s: %s declared but never used"
>% (f.func_name, ','.join(unused)))
> return f
> return decorator
>
>  Used something like this:
>
>  >>> @uses("x y")
>  def f(x):
> y = x+1
> return z
>
>  >>> @uses("x y z")
>  def f(x):
> y = x+1
> return z
>
>
>  Traceback (most recent call last):
>   File "", line 1, in 
> @uses("x y z")
>   File "", line 10, in decorator
> raise ValueError("%s: %s declared but never used" % (f.func_name,
>  ','.join(unused)))
>  ValueError: f: z declared but never used
>  >>> @uses("x")
>  def f(x):
> y = x+1
> return z
>
>
>  Traceback (most recent call last):
>   File "", line 1, in 
>     @uses("x")
>   File "", line 8, in decorator
> raise ValueError("%s: %s assigned but not declared" % (f.func_name,
>  ','.join(undeclared)))
>  ValueError: f: y assigned but not declared
>
>
> >>>
>
>  --
>  http://mail.python.org/mailman/listinfo/python-list
>



-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list

Re: Explicit variable declaration

2008-04-23 Thread Filip Gruszczyński
>  You mean the type? Not in 2.x, but in 3.x, there are function
>  annotations:
>
>  def a_function(arg1: int, arg2: str) -> None: pass

Nope, I don't like types ;-) 3.x seems pretty revolutionary, and this
typing can be appreciated by some people.

> Declaring what about them? If you mean declaring the type, remember
> that Python deliberately allows any name to be bound to any object;
> type declarations can't be enforced without losing a lot of the power
> of Python.

Just declaring, that they exist. Saying, that in certain function
there would appear only specified variables. Like in smalltalk, if I
remember correctly.

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list

Explicit variable declaration

2008-04-22 Thread Filip Gruszczyński
Hello everyone!

It is my first message on this list, therefore I would like to say
hello to everyone. I am fourth year student of CS on the Univeristy of
Warsaw and recently I have become very interested in dynamically typed
languages, especially Python.

I would like to ask, whether there is any way of explicitly declaring
variables used in a function? While I am pretty sure, that there is no
such way in the language itself, I would like to know, whether there
are any third-party tools to do that. This would be very useful for me
during development, so I am looking for such a tool.

-- 
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list