Re: [Tutor] Python 2.7.1 interpreter complains about NameError: global name 'levenshtein_automata' is not defined

2010-12-27 Thread Serdar Tumgoren
It appears that you've defined "levenshtein_automata" as a method on your DFA class, but you did not reference the class instance in your call by prefixing "self". Instead, you're trying to call a globally defined function named "levenshtein_automata" -- which because it is not defined, is throwing

Re: [Tutor] A deeper explanation of ability to modify list elements in-place

2010-11-11 Thread Serdar Tumgoren
First off, thanks for the detailed response! I had a few follow-up questions below, if you're willing to indulge. Feel free to direct me to RTM some books on C and the python source code, of course :) > Why? Because the designer of Python, Guido van Rossum, wanted it to be > possible, and he desi

Re: [Tutor] A deeper explanation of ability to modify list elements in-place

2010-11-11 Thread Serdar Tumgoren
> > > Would you have the same question about what takes place here?: > > >>> list_ = [3,4,5] > >>> list_[1] = 10 > >>> list_ > [3, 10, 5] > >>> > > No surprise there. It's a familiar usage and it appears to be the canonical example (in textbooks/tuts) for demonstrating "in-place" object modificatio

[Tutor] A deeper explanation of ability to modify list elements in-place

2010-11-11 Thread Serdar Tumgoren
Hi folks, I'm trying to gain a deeper understanding of why it's possible to modify list elements in-place *without* replacing them. For instance, why is the below possible? >>> class Dummy(object): ... pass ... >>> a = Dummy() >>> b = Dummy() >>> x = [a, b] # modify list elements in-place >>>

Re: [Tutor] Newbie - regex question

2010-08-30 Thread Serdar Tumgoren
To make a qualifier non-greedy, > simply add an asterix at its end: > > r'WORD1-.*?' > > Hugo explains this nicely, but I just wanted to make one minor correction -- the non-greedy qualifier is the question mark AFTER an the asterisk (which is what Hugo's code shows but I believe he accidentally

Re: [Tutor] Help with Object Oriented Programming

2010-08-30 Thread Serdar Tumgoren
I haven't read it yet myself, but the below book just came out: http://www.amazon.com/Python-3-Object-Oriented-Programming/dp/1849511268/ref=cm_cr_pr_sims_t I'm not aware of any other book that focuses exclusively on OO in Python, though you'll find good intros to the topic in a number of the "cl

Re: [Tutor] is it possible to call a setter property during classinstantiation?

2010-08-13 Thread Serdar Tumgoren
> > > > I have a class with an init method that is getting bloated with >> error-checking guard clauses. >> > > Thats very strange. We don't usually have to check types in Python, > it is a dynamic language and we can use duck-typing and exceptions > so we don't usually care too much about types.

Re: [Tutor] is it possible to call a setter property during class instantiation?

2010-08-12 Thread Serdar Tumgoren
> > def __init__(self, value): > > self.text(value) > > self.text = value # is the way to do this, if you're using it as a > property. > > That worked perfectly! So it seems I was botching the syntax. Many thanks for the quick response!! Serdar

[Tutor] is it possible to call a setter property during class instantiation?

2010-08-12 Thread Serdar Tumgoren
Hey all, Does anyone know if it's possible to call a property setter inside of a class's init method? Below is a code sample of what I'm trying to do. class Question(object); def __init__(self, value): self.text(value) @property def text(self): return self._text

Re: [Tutor] Global name not found, though clearly in use

2010-07-14 Thread Serdar Tumgoren
> > >> > I also found this interesting (but possibly not to newbies :) : > http://www.shinetech.com/attachments/108_python-language-internals.pdf > > Very helpful, especially that last resource. Thank you! Serdar ___ Tutor maillist - Tutor@python.org

Re: [Tutor] Global name not found, though clearly in use

2010-07-14 Thread Serdar Tumgoren
> Hmm..If I add a few debugging lines like that into my code, I get this: >> > > The point was that statements in a class at class level (ie, not in defs) > are executed sequentially and expect referenced variables to exist (ie, > defined somewhere 'above' the current statement) -- there is no for

Re: [Tutor] I don't understand this code

2010-07-14 Thread Serdar Tumgoren
The rest of the list does a great job explaining the situation, which bears out in the code itself. If you look farther down in the code sample in Chapter 9, you'll see the function called twice. http://inventwithpython.com/chapter9/ << snipped >> print('H A N G M A N') missedLetters = '' correct

Re: [Tutor] Django Read

2010-07-08 Thread Serdar Tumgoren
Python Web Development With Django has a good primer on Python (in general and as it relates Django), along with a nice sampling of projects (creating a basic CMS, using Ajax in an application, creating a Pastebin site). You can learn about Django best practices and get a taste for some related to

Re: [Tutor] Unit testing command-line options from argparse or optparse

2010-05-19 Thread Serdar Tumgoren
Ah, okay -- both of those options make sense. I'll try my hand at Jan's first and will report back if I have any problems. Many thanks as always! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.or

[Tutor] Unit testing command-line options from argparse or optparse

2010-05-18 Thread Serdar Tumgoren
Hello all, Does anyone have advice for writing unit tests against variables set by command-line options? I have a program I'd like to run in either "debug" or "live" mode, with various settings associated with each. Below is some pseudo-code that shows what I'd like to do: <> mode = p.parse_args

Re: [Tutor] what is wrong with this code?

2010-04-26 Thread Serdar Tumgoren
> user_tables = ['notification', 'userNotification', 'product_comments', > 'product_donation_paypalTransaction', 'product_donation', > 'productList_recommended', 'productList_user_assoc', > 'profile_values'] > > drop_user_tables = """DROP TABLE IF EXISTS db2.%s""" > > try: >cursor.execute(drop_

Re: [Tutor] Problem iterating over csv.DictReader

2010-04-26 Thread Serdar Tumgoren
> I have noticed this odd behaviour in the CSV DictReader Class, and at a > loss to understand/ get around it. > > The aim is to read in a CSV file, and then iterate over the lines. The > problem (seems) to be that once you have iterated over it once, you can't do > it again. > > This is expected b

Re: [Tutor] accessing Postgres db results by column name

2010-04-12 Thread Serdar Tumgoren
> Wanted to send along one more update about this topic. Steve Orr pointed > out in a comment on Ricardo's new recipe that there's yet another way to get > named attribute access to cursor results. > I should add the disclaimer that namedtuple is only available in Python 2.6+ _

Re: [Tutor] accessing Postgres db results by column name

2010-04-12 Thread Serdar Tumgoren
Hey folks, Wanted to send along one more update about this topic. Steve Orr pointed out in a comment on Ricardo's new recipe that there's yet another way to get named attribute access to cursor results. The secret sauce is namedtuple, "high performance" collection type. This appears to be the "c

Re: [Tutor] Move all files to top-level directory

2010-04-12 Thread Serdar Tumgoren
What fine manual should I be reading? I am not asking for > code, rather just a link to the right documentation. > You'll definitely want to explore the os module, part of Python's built-in standard library. http://docs.python.org/library/os.html http://docs.python.org/library/os.html#files-and

Re: [Tutor] accessing Postgres db results by column name

2010-04-10 Thread Serdar Tumgoren
> I really like Ricardo's solution ... attribute access is a nice touch, > bookmarking it now. > > FWIW, it would seem that psycopg2 also has a DictCursor (and > DictConnection). > > http://initd.org/psycopg/docs/extras.html > > > Ah, yes, there it is. Thank you. This list rocks! __

Re: [Tutor] accessing Postgres db results by column name

2010-04-09 Thread Serdar Tumgoren
Hey everyone, Ricardo was nice enough to post his solution as a recipe on ActiveState. For anyone interested in bookmarking it, here's the link: http://code.activestate.com/recipes/577186-accessing-cursors-by-field-name/ Serdar ___ Tutor maillist - T

Re: [Tutor] accessing Postgres db results by column name

2010-04-09 Thread Serdar Tumgoren
> >>> class reg(object): > ... def __init__(self, cursor, registro): > ... for (attr, val) in zip((d[0] for d in cursor.description), > registro) : > ... setattr(self, attr, val) > > >>> for row in cursor.fetchall() : > ... r = reg(cursor, row) > ... print r.CosCPrd,

[Tutor] accessing Postgres db results by column name

2010-04-09 Thread Serdar Tumgoren
Hi folks, Does anyone know if there's native support in psycopg2 for accessing rows in a result-set by column name (rather than by index)? I'd like to be able to do something like below: cur.execute('select id, name from mytable') data = cur.fetchall() for row in data: print row['id'], row['

Re: [Tutor] Django Book Recommendation

2010-04-07 Thread Serdar Tumgoren
There is lots of good information in the second edition of the official Django Book (though it appears it's only a partially complete Web preview): http://www.djangobook.com/en/2.0/ The Django google group is a great way to research specific questions and get help: http://groups.google.com/g

Re: [Tutor] How do I find information about a Python object.

2010-03-30 Thread Serdar Tumgoren
You might want to check out the below chapter from Dive Into Python: http://diveintopython.org/power_of_introspection/index.html ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinf

Re: [Tutor] split a 5 chars word into 4 and 1

2010-03-09 Thread Serdar Tumgoren
> Hello, > > I'm trying to split 5 chars words (codes) into 2 variables. The first must > contain the first 4 characters. The second variable will only contain the > last character. I'm working in a loop pre-generated codes. > > Any magic command for this ? :-) > > Examples of codes : > 3cmvA > 3cm

[Tutor] Collaborative Comp Sci education using Python

2010-03-05 Thread Serdar Tumgoren
Hey everyone, A while back some folks said they were organizing an online study group to work through Wesley Chun's Core Python. I just stumbled into another online study group that might also be of interest: http://www.crunchcourse.com/class/mit-opencourseware-600-introduction/2010/jan/ The stud

Re: [Tutor] Python-based address standardization script?

2010-02-24 Thread Serdar Tumgoren
> Sure, just send me a link when it's up. I don't have any experience with > git but I've wanted to learn so go ahead and use that. > > Okay - the git repo is here: http://github.com/zstumgoren/python-addressparser You can clone it with the following shell command (assuming you've installed git):

Re: [Tutor] Python-based address standardization script?

2010-02-24 Thread Serdar Tumgoren
> Hey folks, >> Anyone know if there's a Python script floating out there to standardize >> U.S. addresses? I couldn't find anything on ActiveState or by Googling...I'm >> interested in something similar to this Perl module: >> >> http://search.cpan.org/~sderle/Geo-StreetAddress-US-0.99/US.pm

[Tutor] Python-based address standardization script?

2010-02-24 Thread Serdar Tumgoren
Hey folks, Anyone know if there's a Python script floating out there to standardize U.S. addresses? I couldn't find anything on ActiveState or by Googling...I'm interested in something similar to this Perl module: http://search.cpan.org/~sderle/Geo-StreetAddress-US-0.99/US.pm Just curious if anyo

Re: [Tutor] Where to find the article for comparing different Python Development Environment

2010-02-16 Thread Serdar Tumgoren
> Where to find the article for comparing different Python Development > Environment > > The Python wiki is a good place to start: http://wiki.python.org/moin/IntegratedDevelopmentEnvironments ___ Tutor maillist - Tutor@python.org To unsubscribe or cha

Re: [Tutor] Editing html using python

2010-02-15 Thread Serdar Tumgoren
In the few cases I had where BeautifulSoup couldn't handle poorly formed HTML, I've found that html5lib was able to get the job done. And of course, lxml is great too, but has a bit more overhead installation-wis. ___ Tutor maillist - Tutor@python.org T

Re: [Tutor] Tutor list as pair progamming plush toy

2010-02-12 Thread Serdar Tumgoren
In similar vein, I find that a concept suddenly makes more sense to me when I try to explain it to someone else (or I realize that I don't fully understand and need to do some more research). But with regard to the plush toy you mention, I just ran into that anecdote in Coders at Work. Can't recal

Re: [Tutor] correcting an Active State Recipe for conversion to ordinal

2010-02-04 Thread Serdar Tumgoren
> If you want value % 100/10 to give the same result in Python 2.6 and > Python 3 you can use value % 100//10 which will always use integer > division. > Kent, thanks for anticipating this. I actually was struggling to figure out how to update the division and wasn't certain how. Below is the ful

Re: [Tutor] correcting an Active State Recipe for conversion to ordinal

2010-02-04 Thread Serdar Tumgoren
> It now works ok but.. > > You should not use ord as variable as ord() is used by python already. > > Also this will fail in python 3 and 2 with import from future, it does > division differently. from __future__ import division 11 % 100 / 10 > 1.1001 > > So "if value % 100/1

Re: [Tutor] correcting an Active State Recipe for conversion to ordinal

2010-02-04 Thread Serdar Tumgoren
On Thu, Feb 4, 2010 at 1:21 PM, Serdar Tumgoren wrote: >> Perhaps the code on activestate is not a correct copy of what you are >> running? The conditional at line 23 extends all the way to line 35 - >> the end of the function - so if value % 100/10 == 1 no more code is >&

Re: [Tutor] correcting an Active State Recipe for conversion to ordinal

2010-02-04 Thread Serdar Tumgoren
> Perhaps the code on activestate is not a correct copy of what you are > running? The conditional at line 23 extends all the way to line 35 - > the end of the function - so if value % 100/10 == 1 no more code is > executed and None is returned. > Here is the code that I'm running locally (hopeful

Re: [Tutor] correcting an Active State Recipe for conversion to ordinal

2010-02-04 Thread Serdar Tumgoren
> No time to search for the issue, but here are some trials (hole from 10 --> > 19): > for i in range(21): >        print "%s\t: %s" %(i,ordinal(i)) > for i in (-1,22,33,99,100,101,199,200,999,1000): >        print "%s\t: %s" %(i,ordinal(i)) > ==> > 0       : 0th > 1       : 1st > 2       : 2nd >

[Tutor] correcting an Active State Recipe for conversion to ordinal

2010-02-04 Thread Serdar Tumgoren
Hi folks, A few months back I posted my first (and only) "recipe" to ActiveState. It was just a little function to convert an integer or its string representation to an ordinal value: 1 to 1st, 2 to 2nd, etc. Not sure if this really qualifies as a recipe, per se, but it was a handy little functio

Re: [Tutor] [OT] Python Study Group

2010-01-29 Thread Serdar Tumgoren
Sounds like a cool idea David. Is this an online study group or do the folks who signed up live near each other geographically as well? On Fri, Jan 29, 2010 at 3:15 PM, David Abbott wrote: > A group of beginners and intermediate Pythonerrs and getting together to > study the book Core Python Pr

Re: [Tutor] Greetings Pythonistas

2010-01-07 Thread Serdar Tumgoren
Welcome! You've come to the right place. > books at the moment and working through the exercises: Dive into Python by > Mark Pilgrim, and Python Programming - An Introduction to Computer Science > by Zelle. Those are both great books to start with, IMHO. You might want to also check out Beginning

Re: [Tutor] Field/Variable References

2009-12-18 Thread Serdar Tumgoren
> Why negative indexes when fields lengths are known? I'll admit I made a few assumptions based on what I could glean from the OP: * names will vary in length in a questionnaire or poll (which this appears to be) * answers will always be represented by a single digit * area code (at least in US)

Re: [Tutor] Field/Variable References

2009-12-18 Thread Serdar Tumgoren
I'm reposting John's follow-up question (below) to the list. > Thank you - can you please assume that the data provided is the following: > > Columns 1 - 4 = Name (in record 1 of example = "John") > Column 5 = Answer1 (in record 1 of example = "9") > Column 6 = Answer2 (in record 1 of example = "8

Re: [Tutor] Field/Variable References

2009-12-18 Thread Serdar Tumgoren
> Can someone please let me know how to read a file one record at a time (just > say fixed block for now - see small example below) and assign columns to > fields.  Then reference the field names with if-then-else logic. > > Sample Fixed Block File: > > John98762 > John82634 > John11234 > Hi John,

Re: [Tutor] another unit-testing question: regex testing

2009-12-16 Thread Serdar Tumgoren
> I found existing test libs to be difficult to adapt to text > matching/parsing/processing tasks. So I ended up writing my own testing > utilities. But the context is different: it's for a custom matching library, > with pattern objects for which testing tools are methods. Anyway, someone may

Re: [Tutor] another unit-testing question: regex testing

2009-12-15 Thread Serdar Tumgoren
> I often use a list of test cases to drive a single test. Using a > series of tests is just too painful compared to making a simple list > of test cases. I kinda suspected that but wasn't sure. These tests are for a REALLY basic regex and I was having nightmares thinking how many tests would be n

[Tutor] another unit-testing question: regex testing

2009-12-15 Thread Serdar Tumgoren
Hi everyone, To continue on the popular topic of unit tests, I was wondering if it's generally preferable to use a single unit test or a series of unit tests when testing against a regex pattern. In my specific case, I started out with a single test that contained a (growing) list of bad input da

Re: [Tutor] duplication in unit tests

2009-12-09 Thread Serdar Tumgoren
> Yes, this is much better. Notice how much less code it is! :-) Yes, it was amazing to see how much code melted away when I gave up on the OO design. As you and others suggested, clearly this was not the correct approach for this portion of my program. > If you expect unicode input then it makes

Re: [Tutor] What books do you recommend?

2009-12-09 Thread Serdar Tumgoren
To Alan's list, I'd also add Learning Python 4th Edition. It came out in October and covers Python 3 and 2.6, though I'm not sure if it includes the heftier code samples the OP was interested in... On Wed, Dec 9, 2009 at 2:13 PM, Alan Gauld wrote: > > "Khalid Al-Ghamdi" wrote > >> I wan't to buy

Re: [Tutor] What books do you recommend?

2009-12-09 Thread Serdar Tumgoren
> I wan't to buy some books about python 3. Do you have any recommendations? > I started with no previous programming experience, and I've finished a few > tutorials  and I guess I can be considered a beginner. > My problem, though, is I still find it difficult to write meaningful code or > use th

Re: [Tutor] duplication in unit tests

2009-12-08 Thread Serdar Tumgoren
Hi Kent and Lie, First, thanks to you both for the help. I reworked the tests and then the main code according to your suggestions (I really was muddling these TDD concepts!). The reworked code and tests are below. In the tests, I hard-coded the source data and the expected results; in the main p

[Tutor] duplication in unit tests

2009-12-08 Thread Serdar Tumgoren
Hi everyone, I'm trying to apply some lessons from the recent list discussions on unit testing and Test-Driven Development, but I seem to have hit a sticking point. As part of my program, I'm planning to create objects that perform some initial data clean-up and then parse and database the cleaned

Re: [Tutor] Fw: loops

2009-12-08 Thread Serdar Tumgoren
> - Forwarded Message > From: Richard Hultgren > To: tutor@python.org > Sent: Mon, December 7, 2009 2:53:40 PM > Subject: loops > I'm quite new but determined.  Can you explain to me, step by step, what is > going on in the computer in this loop.  I hope I am not being too dumb! > Hmm...

Re: [Tutor] the art of testing

2009-11-25 Thread Serdar Tumgoren
Thanks to everyone for the detailed and varied responses. They really help get me situated in this unfamiliar world of testing. And the more I hear from you folks, the more I start thinking that my confusion arose because I don't have a formal set of requirements and therefore have to wear multipl

Re: [Tutor] the art of testing

2009-11-24 Thread Serdar Tumgoren
> That's a good start.  You're missing one requirement that I think needs to > be explicit.  Presumably you're requiring that the XML be well-formed.  This > refers to things like matching  and nodes, and proper use of > quotes and escaping within strings.  Most DOM parsers won't even give you a

Re: [Tutor] the art of testing

2009-11-24 Thread Serdar Tumgoren
> I'm not really sure where you are going with this? This looks like a > data specification, but you said the data is poorly specified and not > under your control. So is this a specification of a data validator? > The short answer -- yes, these are specs for a data validator. And I should have be

Re: [Tutor] the art of testing

2009-11-24 Thread Serdar Tumgoren
Lie and Kent, Thanks for the quick replies. I've started writing some "requirements", and combined with your advice, am starting to feel a bit more confident on how to approach this project. Below is an excerpt of my requirements -- basically what I've learned from reviewing the raw data using E

[Tutor] the art of testing

2009-11-24 Thread Serdar Tumgoren
Hi everyone, The list recently discussed the virtues of unit testing, and I was hoping someone could offer some high-level advice and further resources as I try to apply the TDD methodology. I'm trying to develop an application that regularly downloads some government data (in XML), parses the dat

Re: [Tutor] search the folder for the 2 files and extract out only the version numbers 1.0 and 2.0.

2009-11-16 Thread Serdar Tumgoren
> Aim: > what is the best way to look into the allFiles directory, and only search > the folder for the 2 files myTest1.0.zip and myTest2.0.zip to extract out > only the version numbers 1.0 and 2.0. > Based on the above file-naming convention, you could get at the version numbers with a combo of st

Re: [Tutor] Do you use unit testing?

2009-11-16 Thread Serdar Tumgoren
> I learned TDD with PyUnit, but since moved to using Ruby, and have > been spoilt by rspec and even cucumber.  My instincts are to write > things test first, but so far I'm not finding PyUnit easy enough to > get going. > The Dive Into Python chapter walks the process of writing/thinking through

Re: [Tutor] Do you use unit testing?

2009-11-16 Thread Serdar Tumgoren
> How many of you guys use unit testing as a development model, or at > all for that matter? >  I just starting messing around with it and it seems painfully slow to > have to write a test for everything you do. Thoughts, experiences, > pros, cons? > I just started with Test-Driven Development mys

Re: [Tutor] A way to search archives?

2009-11-16 Thread Serdar Tumgoren
> Is there a way to search the archives? Not sure if someone's developed an official search resource, but I've always found Google search to work well: site:http://mail.python.org/pipermail/tutor/ ___ Tutor maillist - Tutor@python.org To unsubscribe

Re: [Tutor] Retrieving information from a plain text file (WinXP/py2.6.2/Beginner)

2009-11-02 Thread Serdar Tumgoren
Hi Katt, It appears you did not return the list of reminders that you extracted in the "read_reminders" function, but simply printed them from inside that function. If you modify your code as below to store the list in a variable called "reminders", you should be able to access the list in your

Re: [Tutor] Generating unique ID

2009-10-28 Thread Serdar Tumgoren
> I'm writing an application which will hold a database of people. Ofcourse, > people can have the same name, so I want to stock them with an unique ID. > If you're using an actual database rather than a plain old text file, you can let the database do the work for you. Most flavors (sqlite, post

Re: [Tutor] HttpResponse error

2009-10-26 Thread Serdar Tumgoren
> Exception Type: SyntaxError at / > > Exception Value: ("'return' outside function", > ('c:\\Users\\Vincent\\Documents\\django_bookmarks\\..\\django_bookmarks\\bookmarks\\views.py', > 15, None, 'return HttpResponse(output)\n')) > The Error message indicates that you've diagnosed the problem corre

Re: [Tutor] introspecting an object for method's name?

2009-10-19 Thread Serdar Tumgoren
> Or just use the built-in logging module which lets you specify > the containing function name as one of its formatting keywords: > > http://docs.python.org/library/logging.html#formatter-objects > Aha! I had skimmed the logging docs, but hadn't gone far enough down to notice the %(funcName)s for

[Tutor] introspecting an object for method's name?

2009-10-18 Thread Serdar Tumgoren
Hi everyone, I'm trying to create a generic logging function, and I'm able to get at the name of the module and class using the built-in attributes __module__, __class__, and __name__. But I wasn't sure how to also grab the name of the function or method, so that when an error occurs, I can log th

Re: [Tutor] way to see code execution in real-time?

2009-10-16 Thread Serdar Tumgoren
l try CodeInvestigator to see if that will do the trick. Meantime, thanks as always! Serdar On Fri, Oct 16, 2009 at 1:29 PM, Alan Gauld wrote: > > "Serdar Tumgoren" wrote > >> I was wondering -- is there a way to "watch" a program execute by >> piping

[Tutor] way to see code execution in real-time?

2009-10-16 Thread Serdar Tumgoren
Hello everybody, I was wondering -- is there a way to "watch" a program execute by piping a report of its actions to standard output or to a file? Basically, I'd like to see the order that functions/methods are executing as they happen, along with how long each one takes. Is this something cProfi

Re: [Tutor] [OT] Secure coding guidelines

2009-10-13 Thread Serdar Tumgoren
> In reference to this tip,  my question is why? > - don't use string formatting to create SQL statements - use the > two-argument form of execute() to pass args as a sequence > SQL injection is the primary reason: http://en.wikipedia.org/wiki/SQL_injection If you are going to "manually" hit a

Re: [Tutor] Bounces

2009-10-08 Thread Serdar Tumgoren
I got an error bounce too, saying that the bottom portion of a recent message was "ignored" ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Help or Advice on MySQL, Python and test data storage

2009-10-08 Thread Serdar Tumgoren
> looking for some advice on using Python with MySQL for test data > storage. What builds of Python work well with MySQL and what modules > allow the connection to the database and data transfer activities. You'll need the MySQLdb module to connect to MySQL from Python. http://sourceforge.net/

Re: [Tutor] What language should I learn after Python?

2009-10-07 Thread Serdar Tumgoren
> http://lambda-the-ultimate.org/node/3465 > Sorry - another brain lapse on my part: the correct author is Peter Van Roy ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] What language should I learn after Python?

2009-10-07 Thread Serdar Tumgoren
And in case you hadn't heard enough suggestions yet, here's something I just stumbled into this morning: Programming Paradigms for Dummies, by Peter Norvig http://lambda-the-ultimate.org/node/3465 Here's a portion of the soundbite from the website (where you can download the PDF): "This chapter

Re: [Tutor] What language should I learn after Python?

2009-10-06 Thread Serdar Tumgoren
Sorry, forgot the link: Programming from the Ground Up http://savannah.nongnu.org/projects/pgubook/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] What language should I learn after Python?

2009-10-06 Thread Serdar Tumgoren
Well, it's admirable that you're wiling to stick with it and learn something new. One other resource that I've personally been meaning to look into but just haven't had time is Programming from the Ground Up. It teaches computer science using Assembly language, quite literally from the "ground up.

Re: [Tutor] advice on structuring a project

2009-10-06 Thread Serdar Tumgoren
> I don't think there is a "right" answer to this question. It depends > on how the classes are used and related to each other. If the Auto > classes are related or if they are useful to more than one client, > perhaps you should make an auto_models.py to hold them. If they are > only useful to ind

Re: [Tutor] What language should I learn after Python?

2009-10-06 Thread Serdar Tumgoren
Hi Mark, I recently started dabbling with Java, which has some great texts on object-oriented design and patterns (a skill that I'm finding helps with Python). If you have time on your hands, you might want to consider learning a programming language that has a different philosophy or approach th

[Tutor] advice on structuring a project

2009-10-06 Thread Serdar Tumgoren
Hi everyone, I was wondering if anyone could offer advice as I try to simplify a project I've been working on. I have a set of classes that I've named models.py (following the Django convention, though it's not technically a Django project or app). Inside that file, I had initially grouped toget

Re: [Tutor] Novice qustion

2009-09-24 Thread Serdar Tumgoren
>>  File "test.py", line 18 >>    print format % (item_width, 'Dried Apricots (16 gr)' price_width, 8) >>                                                                   ^ >> SyntaxError: invalid syntax Oxymoron has pointed you in the right direction. After you fix that error, however, you'll get

Re: [Tutor] how to print a message backwards

2009-09-24 Thread Serdar Tumgoren
> Does anyone have an advanced topic on slicing where the :: notation is > explained? > You should find plenty by googling for "python slice step sequence" Here are a few with links to further resources: http://www.python.org/doc/2.3/whatsnew/section-slices.html http://stackoverflow.com/questions

Re: [Tutor] how to print a message backwards

2009-09-23 Thread Serdar Tumgoren
> http://docs.python.org/tutorial/introduction.html#strings > The below page is a better introduction to sequences: http://effbot.org/zone/python-list.htm It uses lists, but the lessons on slicing also apply to strings (which are a type of sequence). HTH! Serdar

Re: [Tutor] how to print a message backwards

2009-09-23 Thread Serdar Tumgoren
Try reading up on sequences and slicing. They offer a very elegant solution to your (homework?) problem. http://docs.python.org/tutorial/introduction.html#strings ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
>   def add_name(self): >       try: >           self.name = SPECIALIZED_SQLcall_for_child() >       except SpecialSQLError: >           #default to the superclass's add_name method >           super(Child, self).add_name() > That certainly is a lot easier to read. So if I were to go that route, wo

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
>>>            self.name =ame > > I assume this is a typo? And it never gets executed because the error is > always raised. yep. that was a typo that should be "name" > I don't mind using exceptions for a simple test but not where the test is > being forced by a piece of code that does nothing. I

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
> An "if" test would be more readable, I agree.  But I was trying to > apply the "Easier to Ask Permission Forgiveness" style, discussed in > the Python Cookbook: , > Err..."Easier to Ask Forgiveness than Permission" approach is what I meant (perhaps proving my point about not fully understanding t

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
> I know this is a simplified example, but I'd still like to point out that > using exceptions when there's a simple test is not reasonable.   You can > just check for None with a simple if test. An "if" test would be more readable, I agree. But I was trying to apply the "Easier to Ask Permission

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
> I know that when you need super(), you have to use it everywhere. So I > would stick with what you have. > > Kent > Okay. Thanks as always to all. Best, Serdar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http:

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
> I prefer the older approach too, it is simple and explicit. super() > comes with a raft of complications (google "super considered harmful") > and AFAIK it is only really needed in the case of "diamond" > inheritance. > The explicit method does indeed seem...well...more explicit and easier to und

Re: [Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
> You're actually already doing it:  look at __init__. > > __init__ is overridden in your subclass, so you call super(Child, > self).__init__() to initialise the class using the parent > (superclass)'s __init__ method. Yes indeed. Thanks for pointing it out. In case it helps anyone else out down t

[Tutor] calling a superclass method after overriding it

2009-09-22 Thread Serdar Tumgoren
Hi everyone, Is there a way to call a superclass method after I've overridden it in a subclass? Specifically, what I'm trying to is something like the following: class Parent(object): def add_name(self): self.name = result_of_GENERIC_SQLcall() class Child(Parent): def __init__(se

Re: [Tutor] breaking out of a function that takes too long

2009-09-15 Thread Serdar Tumgoren
Thanks to all for the responses. I've never used threading, but from some initial googling it appears that it can indeed by tricky and there seem to be numerous recommendations against killing threads or processes. I'll explore the socket request libraries mentioned by several to see if that does

[Tutor] breaking out of a function that takes too long

2009-09-15 Thread Serdar Tumgoren
Hey everyone, Is there a way to break out of a function if it exceeds a certain time limit for execution? There's a Website I'm scraping on a regular basis, and for some reason that I can't divine the site has radically varying response times. In some cases, I get a result vary quickly; at other t

Re: [Tutor] Poorly understood error involving class inheritance

2009-09-10 Thread Serdar Tumgoren
> When you sub "int" for "str", it seems to work. Is there a reason > you're not just subclassing "object"? I believe doing so would give > you the best of both worlds. > Of course, I should qualify the above -- the "str" subclass inherits very different methods than "int" or "object". http://doc

Re: [Tutor] Poorly understood error involving class inheritance

2009-09-10 Thread Serdar Tumgoren
class dummy2(str): > ...     def __init__(self,dur=0): > ...             self.dur=dur > ... z=dummy2(3) z.dur > 3 > > So far so good.  But: > z=dummy2(dur=3) > Traceback (most recent call last): >  File "", line 1, in > TypeError: 'dur' is an invalid keyword argument for this f

Re: [Tutor] Getting list of attributes from list of objects

2009-09-10 Thread Serdar Tumgoren
> I have the following list > > l= [ a, b, c] > > Where a,b,c are objects created from one class, e.g. each has title > attribute. > What I want to have is a list of titles, e.g. [a.title, b.title, c.title] > > Is there a quick way to do it? Or I should use loops (looping through each > element, an

[Tutor] use case for graphs and generators?

2009-09-08 Thread Serdar Tumgoren
Hi everyone, I was hoping someone could advise on whether I'm tackling a specific problem in the correct manner. Specifically, I'm trying to use a "clean" set of historical data to fix omissions/errors among a stream of newer data. To do so, I've devised a series of backend SQL statements which ne

Re: [Tutor] flyweight pattern using Mixin vs. Inheritance

2009-08-28 Thread Serdar Tumgoren
class A: > instances = {} > def __new__(self,ID): > if ID in self.instances: > return self.instances[ID] > else: > self.instances[ID] = self > return self > def __init__(self, ID): > if ID not in self.instances: > print("unregistered instance!") > def __del__(self): > del(self.instances[self.I

Re: [Tutor] flyweight pattern using Mixin vs. Inheritance

2009-08-28 Thread Serdar Tumgoren
I was able to resolve the error by explicitly naming the class in the dictionary lookup inside __new__: if candid in CandidateAuto.instances: return candid I'm curious why this is necessary though. From our earlier dicussions (and from other reading), I thought that by declari

  1   2   >