Re: Any Good tools to create CSV Files?

2007-04-29 Thread Bart Willems
Carsten Haese wrote:
> You mean something like the csv module that is part of Python's standard
> library?
> 
 import csv
 help(csv)

You have to admit, the module name is not really intuitive... :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I have a chance to do somting diffrent way not Python ?!

2007-04-29 Thread Bart Willems
anders wrote:
> So basicly i like advice about interac with os, compiler etc.
> Nice webblinks to read more
> and do/don't things.
Hello Anders,

OS Support for Windows in Python is excellent. I suggest you download 
the latest version, and don't forget to download Mark Hammond's win32 
library as well. Although it is mainly about COM support and you 
probably don't need it, it is always good to have.

After that, work your way through the tutorial. It should give you 
enough information to create the scripts that you need. I used the 
Manning book to learn Python, but I hear a lot of good stories over here 
from 'Python for dummies' as well.

The modules (included in the installation package) that you will need in 
your scripts are probably os, sys, and maybe some of the date modules.

I can't think of any "don'ts" - except maybe for the warning that you 
should not try to write java or c++ code in Python. So, if there is 
anything that seems to me missing, consider a different approach in your 
code (a good example is the switch statement...)

Best regards,
Bart
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: if __name__ == 'main': & passing an arg to a class object

2007-04-29 Thread Bart Willems
gtb wrote:
> appear at the end of many examples I see. Is this to cause a .class
> file to be generated?
This might be obvious, but no one else mentioned it: the Python 
interpreter cannot execute code that it hasn't compiled yet, which is 
why the "if __name__ ..." code is always at the end of the module - to 
guarantee that the entire file is scanned first.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any Good tools to create CSV Files?

2007-04-29 Thread Bart Willems
Aahz wrote:
> In all fairness, the csv module is new in Python 2.3, and I'm sure I'm
> not the only person still using Python 2.2 for production.
That is true, on the other hand, Reportlab is made for at least Python 
2.4, "although it will work with 2.3" - so he has 2.3 at least :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Chart drawing tool in python

2007-04-29 Thread Bart Willems
[EMAIL PROTECTED] wrote:
> Hi,
> 
> In Perl, there is a GD module to draw custom chart.
> http://www-128.ibm.com/developerworks/opensource/library/os-perlgdchart/?ca=dgr-lnxw01Perl-GD-Charts
> Can you please tell me if there is an equivalent library in python?

Did you take a look at reportlab? (http://www.reportlab.org) Besides PDF 
also output in bitmap format, and there is a lot of customization possible.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python win32com excel problem

2007-05-01 Thread Bart Willems
Ray wrote:
> Hi,
> I tried to call "xlApp.Columns.AutoFit=1" the whole program will crash,
> but without xlApp.Columns.AutoFit=1, everything just fine.

Autofit is a method. Also, columns are a method of a worksheet - try:
xlApp.Worksheets.Columns("C:K").Autofit()
(or whatever columns you need of course)

> 2. How do I set a rows format? I need to set row "F" to "Text", "o","p" 
> to general, and
> "Q", "R", to currency.

Same story: you will need to define the range first.
xlApp.Worksheets.Rows("10:200").Numberformat = "General"
I think that you actually mean columns, and not rows - columns have 
character designators, rows have numbers. In that case, try something 
like xlApp.Activesheet.Columns("F") = "@" (text format), or the other 
appropiate codes for number formatting as required. I usually pick 
"#,##0.00" to display numbers with two decimals and thousands seperators.

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


Re: python win32com excel problem

2007-05-01 Thread Bart Willems
Bart Willems wrote:
> Autofit is a method. Also, columns are a method of a worksheet - try:
> xlApp.Worksheets.Columns("C:K").Autofit()

Silly me. That is of course xlApp.Activesheet.Columns("C:K").Autofit()

On a sidenote, you can refer to a worksheet with xlApp.Worksheets(Name) 
as well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why stay with lisp when there are python and perl?

2007-05-07 Thread Bart Willems
Xah Lee wrote:
 > blah blah blah blah blah lisp blah blah blah
 > blah blah lisp blah blah. Blah blah? Blah blah!
 > blah blah blah blah blah;
 > 1) Blah lisp.
 > 2) Blah blah.
 > 3) Blah lisp blah.
 > blah blah blah blah blah. Blah blah lisp! Blah lisp!
 > Blah lisp! Blah! Blah blah blah! Lisp blah blah!

Ok. I give up. WTF is this being cross-posted in the Python forum?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-list Digest, Vol 42, Issue 117

2007-03-09 Thread Bart Willems
I'm sorry, but what's wrong with:
radix = [ [] ] * 256

Cheers,
Bart

"John"  writes:
>> For my code of radix sort, I need to initialize 256 buckets. My code looks a 
>> little clumsy:
>>
>> radix=[[]]
>> for i in range(255):
>> radix.append([])
>>
>> any better code to initalize this list? 
>> 
>
> Typically you'd say 
>radix = [[] for i in xrange(256)]
>
>   


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


Re: any better code to initalize a list of lists?

2007-03-11 Thread Bart Willems
Donald Fredkin wrote:
> John wrote:
> 
>> For my code of radix sort, I need to initialize 256 buckets. My code
>> looks a little clumsy:
>>
>> radix=[[]]
>> for i in range(255):
>>radix.append([])
>>
>> any better code to initalize this list?
> 
> radix = [[[]]*256][0]
> 

No I fell for that one too - it's the same as 'radix = [[]] * 256. Try 
radix[0].append('dead parrot')..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem I have with a while loop/boolean/or

2007-03-13 Thread Bart Willems
John McMonagle wrote:
> Try it a different way:
> 
> while True:
> hint = raw_input("\nAre you stuck? y/n: ")
> hint = hint.lower()
> if hint != 'y' and hint != 'n':
> print "Please answer y or n"
> continue
> else:
> break
> if hint == 'y':
> do_your_hint_stuff()


I always try to stay away from 'negative' operators if possible, to 
improve readability:

while True:
hint = raw_input('\nAre you stuck? y/n: ').lower()
if hint = 'y' or hint = 'n':
   break
else:
   print 'Please answer yes or no'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Technical Answer - Protecting code in python

2007-03-21 Thread Bart Willems
Steven D'Aprano wrote:
> Protect it from what? Viruses? Terrorists? The corrupt government? Your
> ex-wife cutting it up with scissors? People who want to copy it? People
> who will look at your code and laugh at you for being a bad programmer?
> 
> Until you tell us what you are trying to protect against, your question
> is meaningless.
> 
> Is your program valuable? Is it worth money? Then the 90% of script
> kiddies will just wait three days, and download the program off the
> Internet after the real hackers have broken your protection.
> 
> If it is NOT valuable, then why on earth do you think people will put up
> with whatever "protection" you use? Why won't they just use another
> program?

Some of us live in a world where consultants get paid for the work they 
do /by clients/. That work might be delivering the solution to some kind 
of problem. Whatever that problem is, a Python script can apparently 
solve it. Just to give a few ideas: grabbing data from a web server, 
converting output from system x in such a way that it can be used by 
system y, etc.

Now - and I know this will take a enormous leap of imagination, but try! 
try! - imagine that whatever the original problem was, it has changed. 
Maybe server x has changed into server z. Maybe the web page that we're 
pulling data from has a different format now. We don't know.

The consultant will leave a program that is of course highly 
configurable so that the client can make simple changes him/herself. He 
has to, as his clients will stop doing business if they have to call him 
for every fart they let out.

However, there can also be more complex cases. What the consultant wants 
is that the client will call HIM to fix the problem, not the director's 
nephew who took two weeks of classes.
Or the consultant wants to be sure that the two dimwitted nimcumpoops at 
the office who /think/ they can write code don't screw up the script 
when they're trying to 'fix' or 'improve' something. And blame the 
consultant if the script all of a sudden stops working 'we did not do 
anything. It just stopped working all of a sudden'.
Or he doesn't want to expose the passwords needed to logon to the 
database server. Or whatever.

So, there are reasons enough why someone wants to render his code 
immutable and/or unreadable *to some extent*. He doesn't have to fear 
reverse engineering by decompiling assembly code. If the 'hacker' can do 
that, he can probably put the whole script together. The consultant's 
problem are the people who shouldn't be touching or reading the script 
because they have no clue what they are doing and want to 'help' anyway. 
The OP clearly states that he does not want a discussion as to why to 
protect the code. All he wants is something that turns 'readable, 
changeable python' into 'unreadable, immutable python'. Yes, there are 
ways to get around it, but that is not his 'target audience' for the 
'protection'.

Yes, I do smell a troll, but not in the original mail.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why brackets & commas in func calls can't be ommited? (maybe it could be PEP?)

2007-03-22 Thread Bart Willems
dmitrey wrote:
> 1st still is shorter by 1 char; considering majority of people use
> space after comma & number of parameters can be big it yileds
> foo bar baz bar2 bar3 bar4
> vs
> foo(bar, baz, bar2, bar3, bar4)

I think most readers already agree on the ambiguities part. Now, for the 
length of the code...
I agree that in you example the first syntax yields a full /five/ spaces 
less than the second syntax. However, it ignores the fact that if you 
are creating functions with that many arguments, you are probably doing 
something wrong. Can't those arguments be provided as a list?
Let's see what is shorter:

foo bar baz bar2 bar3 bar4
or
foo *bars

Not to mention that it might (or might not) be a good idea to wrap the 
function in some kind of class where you can specify a whole bunch of 
attributes, so that you do not have to call a function with that many 
arguments to start with.

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


Re: Technical Answer - Protecting code in python

2007-03-22 Thread Bart Willems
Aaah, *now* we're getting somewhere... :-)

>> All he wants is something that turns 'readable, 
>> changeable python' into 'unreadable, immutable python'.
> 
> chown scriptuser script.py  # a unique user
> chmod a-rwx script.py
> chmod u+rx script.py
> 
> I believe that fully meets the functional requirements. Where shall I send
> the invoice?

If it works on the target machine - I am under the assumption that the 
client is some kind of government office - more likely to run Windows 
than it is to run unix/linux/etc.

Who has a similar solution for windows?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What are OOP's Jargons and Complexities

2007-03-31 Thread Bart Willems
> 
> Even better: pick one entry of your choice from
> 
> http://images.google.com/images?q=%22don%27t+feed+the+troll%22
> 
> 
> Michele

OMG and here I am thinking that Ken Rockwell's site is full of crap. 
This one's worse... Does the guy have a job? Or a life?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reverse engineering Excel spreadsheet

2007-04-02 Thread Bart Willems
John Machin wrote:
> I'm a bit puzzled by your notion of creating a dependency graph
> *without* first extracting the "relationships (functions)" [which you
> could do only by parsing the formulas and macros].

Not really. The range object in the Excel object model has a Dependents 
  attribute, although for creating a graph you might want to rely on 
DirectDependents for obvious reasons. There's no reason to parse
You can use that for each cell to get a list of the cells that have 
their formulas depending on the cell you are interrogating. There's also 
a Precedents and DirectPrecedents property if you want to walk the trees 
in the other direction. :-)

More important, get some *serious* books about Excel VBA programming (I 
can recommend Walkenbach's Power Programming). Excel has a an extremely 
complex object model that can do almost anything for you - writing code 
against Excel without knowledge of that data will mean that you'll be 
writing 100 lines of Python code (for instance, to parse formulas) to do 
something that could have been done in 5 lines of Visual Basic code (or 
Python for that matter, but I can make a better point by using VBA :) ).

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


Re: Why NOT only one class per file?

2007-04-06 Thread Bart Willems
Steven D'Aprano wrote:
> On Wed, 04 Apr 2007 14:23:19 -0700, Chris Lasher wrote:
> 
>> A friend of mine with a programming background in Java and Perl places
>> each class in its own separate file in . I informed him that keeping
>> all related classes together in a single file is more in the Python
>> idiom than one file per class. He asked why, and frankly, his valid
>> question has me flummoxed.
> 
> 
> Hah! Writing one class per file is for wimps! When I program, I write one
> *method* per file, then import them and build the class at runtime.
> 
> I have a friend who writes one *line* per file, then pulls them all
> together with exec(), but that's just being stupid.
> 
> 
> 
I guess you're one of those sissies who uses EDLIN as an editor.

REAL programmers use COPY CON: ... :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuples are useless???

2007-04-08 Thread Bart Willems
James Stroud wrote:
> ... It boils down to the fact that tuples are useless as a 
> result unless you know you really need them--and you never really NEED 
> them.

Could you clarify that for me? I use tuples *a lot* and I really *NEED* 
them - I'm building a lot of multi-tier reports where detail-level data 
is pulled out of a dictionary based on a composed key. It is impossible 
to build those dictionaries *without* using tuples.

So, I *need* those tuples, and they're far from useless to me.

For the rare, rare, rare cases where I *would* need an index function on 
a tuple (I've never needed it):

class IndexTuple(tuple):
   def index(n):
 # your code goes here

would be sufficient, wouldn't it?

Best regards,
Bart
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple integer comparison problem

2007-04-14 Thread Bart Willems
> if points > 89 and points <= 100:
> return "A"
> elif points > 89 and points <= 89:
> return "B"
> elif points > 69 and points <= 79:
> return "C"
> elif points > 59 and points <= 69:
> return "D"
> else:
> return "F"

The previous posters already pointed out your int problem. However, the 
if-statement can be written with a lot less clutter:

if points > 100:
 return "Illegal score"
elif points > 89:
 return "A"
elif points > 79:
 return "B"
elif points > 69:
 return "C"
elif points > 59:
 return "D"
else:
 return "F"

I have a feeling that there's a Python-solution that is shorter yet 
better readable, I just can't figure it out yet...
-- 
http://mail.python.org/mailman/listinfo/python-list


That might be the case for more complex objects...

2007-04-14 Thread Bart Willems
Dennis Lee Bieber wrote:
> On 14 Apr 2007 06:35:34 -0700, "jamadagni" <[EMAIL PROTECTED]> declaimed
> the following in comp.lang.python:
>   In Python, the "variable" NAME does NOT define storage; unlike most
> other classical languages where the "variable name" is a storage
> address, and the value of the RHS is COPIED to that address. Python does
> not do such copying. Names are references to the RHS object itself.
> 
>   a = 5
> 
> means that somewhere in memory is an integer object with the value "5";
> the name "a" is now "pasted onto" that integer object.
> 
>   b = a
> 
> finds the object that has the name "a" stuck to it, and sticks a second
> name "b" onto the same object. There is still only one "5" in memory.

I can try this in interactive mode:
 >>> a = 5
 >>> b = a
 >>> a += 1
 >>> print b
5

So, if /a/ and /b/ where pointing to the *same* "5" in memory, then I 
would expect b to be increased, just as a. But after increasing a, b is 
still 5...

Lists behave as described above, integers and floats don't.

By the way, a classic language like C has features like this too; 
they're called pointers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Combinate 2 lists to a dict ?

2007-04-18 Thread Bart Willems
Jia Lu wrote:
>  I have 2 lists,
>  a = [1,2,3]
>  b = ["ooo","aaa","ppp"]

reading the documentation might help.

If that doesn't work, try d = dict(zip(a, b))
-- 
http://mail.python.org/mailman/listinfo/python-list