Re: [Tutor] KeyError: '61.135.168.82' with dictionary.

2010-03-25 Thread Andreas Kostyrka
Am Donnerstag, 25. März 2010 13:31:07 schrieb Hugo Arts: > On Thu, Mar 25, 2010 at 12:24 PM, Ray Parrish wrote: > > As you can see, it is tossing a key error on the same ip address that was > > used in the interactive code successfully, > > > > I can not figure out what to change to make the scrip

Re: [Tutor] lazy? vs not lazy? and yielding

2010-03-04 Thread Andreas Kostyrka
Am Mittwoch, 3. März 2010 21:41:34 schrieb Dave Angel: > John wrote: > > Hi, > > > > I just read a few pages of tutorial on list comprehenion and generator > > expression. From what I gather the difference is "[ ]" and "( )" at the > > ends, better memory usage and the something the tutorial label

Re: [Tutor] Any Tutor there ? Removing redundant parameters in a models file having include files.

2010-03-01 Thread Andreas Kostyrka
> > Why people use proprietary python ? Well, AFAIK I know, all more or less popular non-Ansi-C implementations of Python are free. (Jython is, IronPython too, although I've never checked in detail, stackless is, PyPy is too, ...) > > It's better to spent energy to participate with the core deve

Re: [Tutor] Getting caller name without the help of "sys._getframe(1).f_code.co_name" ?

2010-02-16 Thread Andreas Kostyrka
Am Samstag, 13. Februar 2010 16:56:08 schrieb patrice laporte: > Hi, > > Being in an exeption of my own, I want to print the name of the caller, and > I'm looking for a way to have it. > > I've found a lot of recipe all of them using what seems to be, according to > me, a not so good trick : all

Re: [Tutor] Compile py to exe in ubuntu

2010-02-11 Thread Andreas Kostyrka
Am Donnerstag, 11. Februar 2010 15:42:31 schrieb Harya Dananjaya: > On 11/02/10 17:47, Timo wrote: > > I use py2exe to compile my Python/PyGTK application. > > I build it on my Windows XP machine and it works on Windows 2000 to > > Windows 7 without installing anything else (like Python). > > > > T

Re: [Tutor] Compile py to exe in ubuntu

2010-02-11 Thread Andreas Kostyrka
Am Donnerstag, 11. Februar 2010 12:44:48 schrieb Harya Dananjaya: > On 11/02/10 17:34, Alan Gauld wrote: > > What would you do with Java? It too is cross platform but requires a > > JVM to be installed on every platform. Python is similar. > > OK, but python need 3rd praties library, and may be th

Re: [Tutor] Replacing the string in a file

2010-01-22 Thread Andreas Kostyrka
The modes for updating files are + suffixed. r+ Open for reading and writing. The stream is positioned at the beginning of the file. w+ Open for reading and writing. The file is created if it does not exist, otherwise it is trun‐ cated. The stream is p

Re: [Tutor] need help in python

2010-01-21 Thread Andreas Kostyrka
Am Donnerstag, 21. Januar 2010 18:48:36 schrieb invincible patriot: > hi > I am a student and i need soe help regarding my assignmentif some one can > help me il be glad. You do realize that assignments are things to be done by yourself? This is a mailing list, so just post your questions, but d

Re: [Tutor] First code snipet

2009-07-25 Thread Andreas Kostyrka
Some things: 1) It's Python, not Phython. 2) Slightly shorter solution to your problem: import random input = range(53) random.shuffle(input) print input 3) The important part here is that reimplementing something that is in the standard library does not make sense usually. 4) A more sensible

Re: [Tutor] Splitting strings and undefined variables

2009-02-10 Thread Andreas Kostyrka
Am Mon, 9 Feb 2009 12:05:33 -0800 schrieb Moos Heintzen : > Hello all, > > I was looking at this: > http://www.debian.org/doc/manuals/reference/ch-program.en.html#s-python > > I have a question about the line of code that uses split() > > With the python version, the line below only works if th

Re: [Tutor] Finding the shortest word in a list of words

2009-01-21 Thread Andreas Kostyrka
Am Tue, 20 Jan 2009 09:33:40 -0600 schrieb "Paul McGuire" : No need for a defaultdict, all dicts have a setdefault method that works fine for this assign an empty dict/list as starting point problem: wordlendict = {} for w in words: wordlendict.setdefault(len(w), []).append(w) try: minle

Re: [Tutor] The better Python approach

2009-01-21 Thread Andreas Kostyrka
Am Wed, 21 Jan 2009 05:40:00 -0800 schrieb jadrifter : > >>>a = '1234 5678 1 233 476' > >>>a.split() > ['1234', '5678', '1', '233', '476'] [int(x) for x in a.split()] # [1234, 5678, 1, 233, 476] Andreas ___ Tutor maillist - Tutor@python.org http://mai

Re: [Tutor] python parser

2008-12-22 Thread Andreas Kostyrka
Am Mon, 22 Dec 2008 07:18:41 -0800 schrieb johnf : > I've been in the programming business for over 20 years and I have > never had a need for a parser. But recently I have need to convert > code from one language to a my new language python. What a better > way to learn the new language python

Re: [Tutor] Looping, and Win32com.client

2008-12-19 Thread Andreas Kostyrka
Am Fri, 19 Dec 2008 15:57:49 + schrieb Tim Golden : > Eduardo Vieira wrote: > > Hello, this is my first post in this list and I'm not a programmer, > > but am enjoying learning python. > > I'm trying to make a script to add worksheets to excel files: > > I managed to implement this code: > >

Re: [Tutor] py_compile and chmod +x

2008-12-19 Thread Andreas Kostyrka
Am Fri, 19 Dec 2008 09:01:24 -0500 schrieb "Emad Nawfal (عماد نوفل)" : You are not supposed to compile the main script. pyc files are automatically generated when you import the py file (but not execute it), if you are allowed to write them beside the py file. When a pyc file exists, and it's ne

Re: [Tutor] sys.path.append

2008-12-18 Thread Andreas Kostyrka
Am Wed, 17 Dec 2008 11:17:14 -0500 schrieb "Kent Johnson" : > On Wed, Dec 17, 2008 at 10:20 AM, ppaarrkk > wrote: > > > > I can do this : > > > sys.path.append ( 'C:\dump1' ) > > Note you should use raw strings r'C:\dump1' or double backslash > 'C:\\dump1' because the \ is a string escape c

Re: [Tutor] need to clean a string

2008-12-15 Thread Andreas Kostyrka
Am Mon, 15 Dec 2008 12:43:46 -0800 schrieb johnf : > On Monday 15 December 2008 11:31:12 am Andreas Kostyrka wrote: > > Am Mon, 15 Dec 2008 10:18:28 -0800 > > > > schrieb johnf : > > > Hi, > > > I have a string that I need to extract just the sql >

Re: [Tutor] need to clean a string

2008-12-15 Thread Andreas Kostyrka
Am Mon, 15 Dec 2008 10:18:28 -0800 schrieb johnf : > Hi, > I have a string that I need to extract just the sql > statement. The following is the string > \000\000\000\000\000\000\000\000.\000\000\000\\000\000\000 > \000$\000\000\000\000\000(\000\000\000\000X\000\000\000\000\

Re: [Tutor] Ask a class for it's methods

2008-12-13 Thread Andreas Kostyrka
On Sat, Dec 13, 2008 at 08:03:10AM +, Lie Ryan wrote: > On Sat, 13 Dec 2008 02:59:34 +0100, Andreas Kostyrka wrote: > > > On Fri, Dec 12, 2008 at 06:06:35PM -0500, Shrutarshi Basu wrote: > >> I have a list containing strings like : > >> > >>

Re: [Tutor] Ask a class for it's methods

2008-12-12 Thread Andreas Kostyrka
On Fri, Dec 12, 2008 at 06:06:35PM -0500, Shrutarshi Basu wrote: > I have a list containing strings like : > > func1[] > func2[1,2] > func3[blah] > > I want to turn them into method calls (with numeric or string > arguments) on a supplied object. I'm trying to figure out the best way > to do this

Re: [Tutor] Newbie

2008-07-24 Thread Andreas Kostyrka
On Wednesday 23 July 2008 22:04:57 Alan Gauld wrote: > ""Simón A. Ruiz"" <[EMAIL PROTECTED]> wrote > > > If what you expected was something like: > > > > Hello World! > > Here are ten numbers from 0 to 9 > > 0 1 2 3 4 5 6 7 8 9 Goodbye World! > > > > Then you want that final print statement to not

Re: [Tutor] Why not to use include?

2008-06-08 Thread Andreas Kostyrka
On Sunday 08 June 2008 17:13:21 Dotan Cohen wrote: > 2008/6/8 Kent Johnson <[EMAIL PROTECTED]>: > > On Sun, Jun 8, 2008 at 6:46 AM, Dotan Cohen <[EMAIL PROTECTED]> wrote: > >> I am moving a website from php to python gradually. The first step is > >> replacing the page headers and footers. > > > >

Re: [Tutor] [Fwd: Re: Intercepting methods calls]

2008-06-06 Thread Andreas Kostyrka
On Friday 06 June 2008 18:19:23 you wrote: > On Thu, June 5, 2008 9:39 am, Andreas Kostyrka wrote: > > On Thursday 05 June 2008 00:18:55 Marilyn Davis wrote: > >> You listed __init__ and I'm not sure I know what you mean. > > > > Well, __init__ can assign

Re: [Tutor] [Fwd: Re: Intercepting methods calls]

2008-06-05 Thread Andreas Kostyrka
On Thursday 05 June 2008 00:18:55 Marilyn Davis wrote: > > You listed __init__ and I'm not sure I know what you mean. > Well, __init__ can assign attributes to the instance that are callable. Andreas signature.asc Description: This is a digitally signed message part. ___

Re: [Tutor] Intercepting methods calls

2008-06-05 Thread Andreas Kostyrka
On Thursday 05 June 2008 12:31:56 you wrote: > On Jun 5, 2008, at 6:06 PM, Andreas Kostyrka wrote: > > well, don't return a string :-P > > > > class CallableString(str): > > def __call__(self, *args, **kw): > > return self > > > > And now

Re: [Tutor] Intercepting methods calls

2008-06-05 Thread Andreas Kostyrka
On Wednesday 04 June 2008 18:18:04 you wrote: > > Well, let's start the ball rolling then. > > > > __getattribute__ > > __getattr__ > > Metaclasses > > decorators > > properties > > __init__ > > Okay, I'll bite. I asked here a week or two ago about creating a > custom dummy object that returns a bl

Re: [Tutor] Intercepting methods calls

2008-06-04 Thread Andreas Kostyrka
Simple (untested in the mailer typed): class A: def __getattr__(self, key): if key.startswith("user"): def func(): return key[4:] return func raise AttributeError assert A().userabc() == "abc" Something like that? On Wednesd

Re: [Tutor] Intercepting methods calls

2008-06-04 Thread Andreas Kostyrka
On Wednesday 04 June 2008 07:41:49 Marilyn Davis wrote: > On Tue, June 3, 2008 10:16 pm, Alan Gauld wrote: > > "Laureano Arcanio" <[EMAIL PROTECTED]> wrote > > > >> Is there any way to intercept calls to methods ? like the > >> __setattribute__ > >> medthod does ? > > > > There are several variatio

Re: [Tutor] How to Think Like a Computer Scientist...

2008-06-03 Thread Andreas Kostyrka
On Tuesday 03 June 2008 15:18:39 Michael yaV wrote: > The green horn that I am, last week I started to go through the "How > to Think Like a Computer Scientist" tutorial. I have gotten to Chapter > 3 --Functions' 3.8 Exercises. I think I have the 1st exercise correct > but I'm really not sure. Is t

Re: [Tutor] How to make a python binding for a c library?

2008-05-13 Thread Andreas Kostyrka
Am Montag, den 12.05.2008, 23:31 -0700 schrieb Mark Tolonen: > "tuyun" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > Hi > > I have a library written in C, I want to make a python binding for it. > > But I dont know how to get started. > > Is there any guide or document? > > Is

Re: [Tutor] Little problem with math module

2008-04-22 Thread Andreas Kostyrka
Hmmm, the power function has basically two definitions: a ** n for integer n, pow is defined for all a in R. for real n, pow is defined only for non-negative a. If you think how a**x is derived (as a generalization from a**(p/q)), that makes sense. Basically, a ** (p/q), p > 0, q > 0, gcd(p, q)

Re: [Tutor] HTML Parsing

2008-04-21 Thread Andreas Kostyrka
eeck. Not that I advocate parsing files by line, but if you need to do it: lines = list(file)[16:] or lines_iter = iter(file) zip(lines_iter, xrange(16)) for line in lines_iter: Andreas Am Montag, den 21.04.2008, 14:42 + schrieb linuxian iandsd: > Another horrid solution > > #!

Re: [Tutor] HTML Parsing

2008-04-21 Thread Andreas Kostyrka
If you have a correct XML document. In practice this is rather a big IF. Andreas Am Montag, den 21.04.2008, 10:35 -0700 schrieb Jeff Younker: > On Apr 21, 2008, at 6:40 AM, Stephen Nelson-Smith wrote: > > > On 4/21/08, Andreas Kostyrka <[EMAIL PROTECTED]> wrote: > &

Re: [Tutor] HTML Parsing

2008-04-21 Thread Andreas Kostyrka
, den 21.04.2008, 14:40 +0100 schrieb Stephen Nelson-Smith: > On 4/21/08, Andreas Kostyrka <[EMAIL PROTECTED]> wrote: > > As usual there are a number of ways. > > > > But I basically see two steps here: > > > > 1.) capture all dt elements. If you want

Re: [Tutor] HTML Parsing

2008-04-21 Thread Andreas Kostyrka
As usual there are a number of ways. But I basically see two steps here: 1.) capture all dt elements. If you want to stick with the standard library, htmllib would be the module. Else you can use e.g. BeautifulSoup or something comparable. 2.) Check all dt contents either via regex, or with a .s

Re: [Tutor] Fwd: Simple copy script

2008-04-14 Thread Andreas Kostyrka
line.strip() for line in file: => line will contain '\n' at the end of the string. Andreas Am Montag, den 14.04.2008, 00:08 -0700 schrieb Que Prime: > > This is what I came up with after writing it out and reading the > corresponding functions. I feel I'm close but something is still > awry. >

Re: [Tutor] in-memory pysqlite databases

2008-04-13 Thread Andreas Kostyrka
Am Sonntag, den 13.04.2008, 23:31 +0100 schrieb Alan Gauld: > "Dinesh B Vadhia" <[EMAIL PROTECTED]> wrote > > > Your last paragraph is the gist of my note ie. it's the > > documentation, documentation, documentation. > > I agree it can be very variable in quality. > One of the problems of Open

Re: [Tutor] Google App Engine

2008-04-08 Thread Andreas Kostyrka
To summerize, it's Python 2.5.2, gutted to remove any chance of storing anything local. Plus you can define patterns that get mapped to Python CGI scripts. Included are also a number of APIs e.g. for data storage (that look at first glance visually similiar to Django models), an API to authenticate

Re: [Tutor] capturing exceptions from an exec statement

2008-04-08 Thread Andreas Kostyrka
Python 2.4.5 (#2, Mar 12 2008, 00:15:51) [GCC 4.2.3 (Debian 4.2.3-2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> try: ... exec("raise ValueError") ... except: ... print "raised some exception" ... import sys ... print sys.exc_info() ... ra

Re: [Tutor] MemoryError !!! Help Required

2008-04-07 Thread Andreas Kostyrka
ited[url]: > except KeyError: > #This means the URL hasn't been visited > > that's probably the easiest way to compare dict values. A possible > good idea, if you were going that route (reading each file) is to > create a dir for each 1st char in the url (aft

Re: [Tutor] MemoryError !!! Help Required

2008-04-06 Thread Andreas Kostyrka
Am Montag, den 07.04.2008, 00:32 -0500 schrieb Luke Paireepinart: > devj wrote: > > Hi, > > I am making a web crawler using Python.To avoid dupliacy of urls,i have to > > maintain lists of downloaded urls and to-be-downloaded urls ,of which the > > latter grows exponentially,resulting in a MemoryE

Re: [Tutor] Which Python Script Editor of Choice?

2008-04-03 Thread Andreas Kostyrka
Eric and SPE are also nice. The good thing here is that the majority of IDEs for Python are free. Andreas Am Donnerstag, den 03.04.2008, 16:57 +0100 schrieb Alan Gauld: > "Jeffrey Dates" <[EMAIL PROTECTED]> wrote > > > So as I'm starting to get into writing some scripts, I'm looking for > > rec

Re: [Tutor] asyncore/asynchat

2008-04-02 Thread Andreas Kostyrka
Well, the source is easy enough to read. Although I wouldn't call Twisted a complication. If all you want is your async server Hello World example, asyncore is fine. If you intend to use the stuff for serious things, one usually starts to reinvent/reimplement Twisted anyway. Andreas Am Mittwoch,

Re: [Tutor] Question about Python ORM

2008-04-02 Thread Andreas Kostyrka
There are many as you said yourself. Recommendation: sqlalchemy.org Andreas Am Mittwoch, den 02.04.2008, 16:51 +0530 schrieb hiren kumar: > Hi, > > I am very much new to Python and it's available framework. > > When I search the over net about Python ORM, I found there are so many > ORMs availa

Re: [Tutor] Help Writing a Bill Calculating Program

2008-03-28 Thread Andreas Kostyrka
Hint: When you want help with your homework, you should first try to program something. Pasting the requirements to this mailing list will not help you. Homeworks are there so that YOU learn something. Not that you can prove that you are capable to find someone that does it for you. Andreas Am Fr

Re: [Tutor] Python to C++

2008-03-25 Thread Andreas Kostyrka
strong points for using Python > > > On Tue, Mar 25, 2008 at 2:46 AM, Andreas Kostyrka <[EMAIL PROTECTED]> wrote: > > Well, not exactly. Mixing Python with C/C++ extends the "coverage" that > > you can do with Python. > > > > Andreas > >

Re: [Tutor] Python to C++

2008-03-25 Thread Andreas Kostyrka
Well, not exactly. Mixing Python with C/C++ extends the "coverage" that you can do with Python. Andreas Am Montag, den 24.03.2008, 23:39 -0700 schrieb Tony Cappellini: > Another alternative is Weave > http://www.scipy.org/Weave > > But mixing C/C++ with Python sort of defeats the reasons for us

Re: [Tutor] what is @classmethod and @staticmethod ??

2008-03-24 Thread Andreas Kostyrka
A classical example is a class that can be constructed from different values. Ok, let's implement a special integer class: class MyOwnInteger(object): def __init__(self, value): self.value = value Now, let's say we want to add the possibility to create MyOwnInteger instances from str

Re: [Tutor] what is @classmethod and @staticmethod ??

2008-03-23 Thread Andreas Kostyrka
One usual usage for classmethods are "alternate" constructors. Andreas Am Sonntag, den 23.03.2008, 10:49 -0700 schrieb maser: > Thanks, Andreas. Why do we need to use classmethod/ > staticmethod and where do we need to use them ? > > thanks > iyer > > --- And

Re: [Tutor] Calling super classs __init__?

2008-03-23 Thread Andreas Kostyrka
Am Mittwoch, den 19.03.2008, 10:36 -0300 schrieb Ricardo Aráoz: > Luciano Ramalho wrote: > > Nowadays the best practice for invoking a method from all superclasses > > (yes, multiple inheritance) is this: > > > > class SubClass(BaseClass): > > def __init__(self, t, *args, **kw): > > s

Re: [Tutor] what is @classmethod and @staticmethod ??

2008-03-22 Thread Andreas Kostyrka
Well, it's classmethod/staticmethod in truth, @ is the decorator operator: def testdec(func): return {"funcobj": func} class Abc(object): @testdec def method(): pass assert isinstance(Abc.method, dict) Basically as you can see above, @X before a function definition takes the

Re: [Tutor] Pseudo-functions and dicts

2008-03-22 Thread Andreas Kostyrka
Well, there are basically two ways to go at it. If you want it at module level, you need to generate the functions: sensor = {'sens1': 200, 'sens2': 300} for key in sensor.keys(): def helper(keytofetch=key): return sensor[keytofetch] globals()[key] = helper print sens1() pri

Re: [Tutor] int to string

2008-03-22 Thread Andreas Kostyrka
Beside casting it with str(), you can also use a format string: assert "%d" % 10 == "10" assert "%5d" % 10 == " 10" assert "%05d" % 10 == "00010" In practice % supports a superset of what printf in C provides. Andreas Am Freitag, den 21.03.2008, 17:05 -0700 schrieb elis aeris: > how do I conv

Re: [Tutor] append string

2008-03-22 Thread Andreas Kostyrka
somestring = "ABC" somestring2 = somestring + "D" somestring2 += "EF" assert somestring2 == "ABCDEF" assert somestring == "ABC" assert id(somestring) != id(somestring2) Basically, strings are immutable. If you need to append something to a string, you need to construct a new string object with th

Re: [Tutor] list

2008-03-21 Thread Andreas Kostyrka
Empty? array = [] If you want to assign 10 "None", that would be: array = [None] * 10 Andreas Am Freitag, den 21.03.2008, 17:03 -0700 schrieb elis aeris: > how do I create an empy int array of 10? > ___ > Tutor maillist - Tutor@python.org > http://

Re: [Tutor] Calling super classs __init__?

2008-03-21 Thread Andreas Kostyrka
It does not return them at once. It returns them piece by piece: [EMAIL PROTECTED]:/tmp> cat mro.py class A(object): v=lambda self: "A" class B(object): v=lambda self: "B" class C(B,A): v=lambda self: "C" print C.__mro__ c=C() print c.v() print super(C, c).v() print super(B, c).v()

Re: [Tutor] Calling super classs __init__?

2008-03-20 Thread Andreas Kostyrka
Am Freitag, den 21.03.2008, 21:48 -0500 schrieb tiger12506: Actually, super returns all base classes, all in it's own time. Basically, every class has a member __mro__, that contains a consistently ordered list of classes. super needs the class from where it is being called to locate the right

Re: [Tutor] Python to C++

2008-03-20 Thread Andreas Kostyrka
If you need to rewrite Python code for performance, I'd recommend using Pyrex/Cython. (www.cython.org). It let's you get away with small changes to your code as a starter (Cython is relative compatible syntax-wise with Python), and you can add "C type annotations" as needed. (And no, C++ is not co

Re: [Tutor] Help with a loop

2008-03-18 Thread Andreas Kostyrka
Assuming that len(b) > len(a): >>> zip(itertools.cycle(a), b) [(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e'), (6, 'f'), (1, 'g'), (2, 'h'), (3, 'i'), (4, 'j')] Andreas Am Dienstag, den 18.03.2008, 16:23 +0100 schrieb PyProg PyProg: > Hello, > > I have a little problem, I have two lists: >

Re: [Tutor] hypotenuse

2008-03-13 Thread Andreas Kostyrka
assert 4**0.5 == 2 More generally: nth root of x: x ** (1.0/n) Or even more generally, take the 3rd root of the square of x: x ** (2.0/3.0) And when we are already extending the scope of the mailing list to math basics: 1.0/(x**2) == x**-2 (negating the power gives the inverse.) Andreas Am

Re: [Tutor] Begining Python

2008-03-13 Thread Andreas Kostyrka
Am Mittwoch, den 12.03.2008, 09:39 +0100 schrieb Meftah Tayeb: > hi my friend, > i have active python installed and the python-Win is Ready > but i have a Very Small problem: > i am blind, and i am using a Screen reader > this screen reader use the Microsoft Active Accessibiliti (MSAA) to find >

Re: [Tutor] How to get MAC address using Python at Solaris

2008-03-11 Thread Andreas Kostyrka
Alternatively, follow the recipe at http://www.tech-recipes.com/solaris_networking_tips785.html You can either just copy&paste the script and use that with popen, or you can reimplement it mostly in Python, calling the seperate programs. The basica gist of this seems to be, figure out your IP add

Re: [Tutor] passing arguments to functions - problem with argument order

2008-03-10 Thread Andreas Kostyrka
What you probably want is to pass: writer(None, "field1", "field2") Andreas Am Montag, den 10.03.2008, 16:28 +0100 schrieb [EMAIL PROTECTED]: > And I thought I might get away without using dicts... > > Thanks, Greg > > > > Greg Graham schrieb: > > Paul, > > > > Python does not allow mixing

Re: [Tutor] Problems with ConfigParser set method

2008-03-08 Thread Andreas Kostyrka
As I thought, it does not fail silently. You need something like: if not parser.has_section("feeds"): parser.add_section("feeds") Andreas Am Samstag, den 08.03.2008, 16:46 + schrieb dave selby: > Hi All, > > I am using the ConfigParser module, I can 'get' from a config file > fine, whe

Re: [Tutor] Const on Python

2008-03-07 Thread Andreas Kostyrka
Am Freitag, den 07.03.2008, 21:13 + schrieb Alan Gauld: > Yes but thats not the bit that takes time in my experience its > trying to understand the problem. What exactly am I trying to > do here? Is it a suimulation exercise, a database problem? > A real-time or networking issue? Should my sol

Re: [Tutor] identifying the calling module/function

2008-03-07 Thread Andreas Kostyrka
There are basically a number of things you might want: 1.) sys.argv[0] 2.) __main__.__file__ 3.) sys._getframe The first two will tell which script is the main program. The last one will tell you which function has called you. But as Kent has pointed out, this is rarely a good idea. Actually, it

Re: [Tutor] Const on Python

2008-03-06 Thread Andreas Kostyrka
Yes, the problem is, that these guys are anyway forced to have Python/Erlang developers on board, because of external opensource components they need to maintain. Am Donnerstag, den 06.03.2008, 23:54 + schrieb Alan Gauld: > Actually I'm with the lead here. > > The cost of developing a new fea

Re: [Tutor] Const on Python

2008-03-06 Thread Andreas Kostyrka
Am Donnerstag, den 06.03.2008, 08:35 -0500 schrieb Kent Johnson: > C++ is extremely complex. The good side of this is it gives you > tremendous control - final, const, pass by reference or value, memory > allocation, etc, etc. The bad side is that it is a lot to think about - > should this para

Re: [Tutor] Const on Python

2008-03-06 Thread Andreas Kostyrka
t really need that much a const so i > wont do anything like that to have a const like data. I am very used > to java and c++, thats why i always used acess modifier, but i think i > can live without it now i know that it dont exist in python :P. > > > > On Thu, Mar 6, 2008 a

Re: [Tutor] Const on Python

2008-03-06 Thread Andreas Kostyrka
The answer is slightly more complex. 1.) objects are either mutable or immutable. E.g. tuples and strings are per definition immutable and "constant". Lists and dictionaries are an example of the mutable kind. 2.) "variables", "instance members" are all only references to objects. Examples: # l

Re: [Tutor] Video file metadata? (MP4/WMV)

2008-03-04 Thread Andreas Kostyrka
Don't think so. Do you have any cmdline tool to update the meta data? Alternativly you can naturally embed Win32 components and control them with Python, but I'm not a Windows guy. Andreas Am Dienstag, den 04.03.2008, 14:10 -0800 schrieb Allen Fowler: > Hello, > > I have several hundred WMV vi

Re: [Tutor] help with slice

2008-03-04 Thread Andreas Kostyrka
What you probably want is: [elem_list[2] for elem_list in List] If you are not sure that the list have at least three elements, you can use something like this: [(elem_list + [None, None, None])[2] for elem_list in List] Which will use None as a default value. Andreas Am Dienstag, den 04.03.2

Re: [Tutor] sorting objects on two attributes

2008-03-03 Thread Andreas Kostyrka
Well, this assumes that all named attributes do exist. If not, you need to replace x.attr with getattr(x, "attr", defaultvalue) ;) l.sort(key=lambda x: (x.content_type, x.submit_date)) Now, you can construct a sorted list "t": t = [] for key, item_iterator in itertools.groupby(l, key=lambda x:

Re: [Tutor] Need help with encoder & decryption keys

2008-03-03 Thread Andreas Kostyrka
Well, actually, ssh can also protect private keys with a cryptographic pass phrase. But this is often not what is wanted as it implies that the user needs to provide the pass phrase every time it is used. (Well, that's not the complete truth, man ssh-agent, but that's completely different thing

Re: [Tutor] Need help with encoder & decryption keys

2008-03-03 Thread Andreas Kostyrka
And if it's a string constant, in many cases running strings (Unix program) on the pyc file will reveal it too. All this basically turns down to the problem, that it's hard to embed an encryption key in a program, so that it's not possible to extract it. Notice the the current crop of HDDVD/Blu

Re: [Tutor] user-given variable names for objects

2008-02-28 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Perhaps even nicer: [key for key, evtime in eventData.iteritems() if evtime < time.time()] This way the dictionary iterates over key, value tuples. Andreas Tiger12506 wrote: | I may sound like a know-it-all, but dictionaries *are* iterators. | | [a

Re: [Tutor] for vs while

2007-09-28 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Try: for item in stuff: os.system(item[0]) print item[1] Alternativly: for cmd, msg in stuff: os.system(cmd) print msg Andreas James wrote: > All, > > I have a dumb question...hopefully someone can shed some light on the > diffe

Re: [Tutor] New to Python and Linux

2007-09-26 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Well, chmod 0700 is usually not want you want: a) 0700 gives only read/write/execute rights to the user. Technically for historical reason permissions can be written as an octal number, with the first digit being optional, encoding stuff like setuid/s

Re: [Tutor] Shelve del not reducing file size

2007-07-28 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Eric Brunson wrote: > On Sat, July 28, 2007 4:01 am, Thorsten Kampe wrote: >> * Kent Johnson (Fri, 27 Jul 2007 08:06:33 -0400) >> >>> Barton David wrote: >>> *sigh* I'm really going off Python. >>> In what way is it Python's fault that the

Re: [Tutor] Shelve del not reducing file size

2007-07-28 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Barton David wrote: > Eric Brunson wrote: >> You seem like a smart guy that's having a bad day, so I'm cutting you >> slack. > > Thanks Eric. Yes I did indeed have a bad day (and it got much much worse), > and this is most definitely a case of a ba

Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Alan Gauld wrote: > "Andreas Kostyrka" <[EMAIL PROTECTED]> wrote > >> was, that the only way to have more math courses would be to study >> something with mathematics in the title *g*) > > Thats true o

Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Alan Gauld wrote: > "Tiger12506" <[EMAIL PROTECTED]> wrote > >> Some people need degrees, most people don't. It all depends on what >> they are >> capable of understanding. > > It also depends what they are doing. > Most programmers don't build c

Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Barton David wrote: > Sadly I can't think of a plan B, hence the frustration! Python, as far > as I know, is as good as it gets. And I don't have the courage or the > capability to improve it myself. > > So all I can really do is clasp my hands toge

Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Barton David wrote: > I mean no offense and lay no blame. It's simply that I feel like I've > been led up a nice gentle beach and suddenly I'm dodging boulders at the > bottom of a cliff. > > I've learned to program with Python (and can hardly conce

Re: [Tutor] Shelve del not reducing file size

2007-07-27 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 That's in the nature of the underlying database library used for the shelve. Most dbm implemention on Unix are using a sparse file that is used as hashmap. E.g. compare ls -l versus du of the database file. Now if this is the case, there is no way (wi

Re: [Tutor] Pass variable on command line

2007-07-26 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Alternatively, I prefer something nicer: import optparse p = optparse.OptionParser(usage="%prog [options]") p.add_option("--list1", action="store_const", const=["blue", "red", "green"], dest="worklist", help="use the first setting") p.add_option("--li

Re: [Tutor] Finding the caller

2007-07-26 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 sys._getframe. Andreas jay wrote: > Hello all, > > If I import a module, which has a bunch of simple functions in it, is > there an easy way to find the direct caller from inside one of those > functions? I'm looking to know which script has impor

Re: [Tutor] Working with bash (subversion)

2007-07-18 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 mkarg is quite useful, from time to time. Andreas Luke Paireepinart wrote: > Justin Cardinal wrote: >> I'm trying to write a program that will list all subversion repository >> directories, then issue a command using each directory as an argument,

Re: [Tutor] Basic DB question

2007-07-16 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 DBAPI is an interface standard describing what you can expect in a database access module, like psycopg. Andreas z machinez wrote: > Hi All, > > I am just starting out with Python and was hoping someone could point me > in the direction of reading

Re: [Tutor] reading random line from a file

2007-07-14 Thread Andreas Kostyrka
Well he could implement the indexing into his program and check mtimes to decide if he needs to reindex. But yes, as long the file fits into memory, readlines (or list(file("quotes,txt")) makes more sense. Andreas -- Ursprüngl. Mitteil. -- Betreff:Re: [Tutor] reading random line from a

Re: [Tutor] Python on Windows with SSH for Cisco devices

2007-07-13 Thread Andreas Kostyrka
I haven't done anything like that as I don't use Windows for anything serious. But I see basically no problem, as at least some of the packages you've mentioned are portable to marginal OSes like Windows *g* So my tip would be, start implementing, I personally would probably stick to conch for

Re: [Tutor] From C to Python

2007-07-05 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Well, philosophically every object "name" is a pointer to a PyObject on C level. The only difference is, that you cannot do anything but assign these pointers (no pointer arithmetic) and memory is managed automatically. If you want to know what happen

Re: [Tutor] hash

2007-07-04 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Simple, defining __hash__ on a class allows you to supply a hash value for instances of your class. [EMAIL PROTECTED]:~> cat /tmp/hash.py class X: def __hash__(self): print "HASH CALLED" return 123 print hash(X()) [EMAIL PROTECTED

Re: [Tutor] how long?

2007-07-04 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 You forgot the uncertainty of 1000% :) Actually, Python is relativly easy to learn, but I've known people that were trained by the Arbeitsamt (government employment office), which never, even after months could predict the output of programs like: fo

Re: [Tutor] Calculating Deflection angles

2007-07-04 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Well, first that sounds somehow like a homework assignment, so only some hints: a) work out the underlying math. Consider all special edge cases. b) I'm not completely sure what you need, but a feeling in the stomach tells me that you might need the a

Re: [Tutor] n.isalnum() is failing

2007-07-03 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Consider using something like: try: start, end = int(start), int(end) except ValueError: print "oops it was not a number." Andreas Terry wrote: > Hi! > > I am running Python 2.5, and I have an IF statement in the below program > that does n

Re: [Tutor] (no subject)

2007-06-29 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Please notice the link http://mail.python.org/mailman/listinfo/tutor in the footer of every mailing list mail. It's not really very nice to shoot into a big room with many persons in it "carry me out of the room". Most people prefer to walk out of the

Re: [Tutor] python port scanner

2007-06-25 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Well, take a look at the socket module and nonblocking mode. But truly, it's not a good "first" program, not for Python, not for C. Andreas max . wrote: > hello i am looking into writing a simple python port scanner but i cant > find > any good tuto

Re: [Tutor] sockets

2007-06-17 Thread Andreas Kostyrka
Tip: consult the documentation of the struct module. Andreas -- Ursprüngl. Mitteil. -- Betreff:[Tutor] sockets Von:"Linus Nordström" <[EMAIL PROTECTED]> Datum: 17.06.2007 22:47 Hello I'm trying to rewrite a chat-program i did in school this spring in python, the school progr

Re: [Tutor] Class error

2007-06-17 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Well, Python is not Java :) Unqualified names reference always only objects defined in the local module by default. If you want to use unqualified names, you could do something like that: from AddrBookEntry import AddrBookEntry or import AddrBookE

  1   2   >