Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
bitprophet
Jul 22, 2004
Taco Defender

Centipeed posted:

Do I have to use a def __init__(self) or something?

Yes! :) That's exactly it.

code:
class Foo(object): # note: never just do "class ClassName:", always inherit from object
    def __init__(self, x):
        self.x = x

    def bar(self):
        return self.x
code:
>>> foo = Foo(5)
>>> foo.bar()
5

Adbot
ADBOT LOVES YOU

bitprophet
Jul 22, 2004
Taco Defender
The general way to fix it is to ensure that proj is on your PYTHONPATH and then to from proj.other import generic.

Relative imports will be a slightly more portable way to do this once they are part of the mainstream* but until that happens, you're stuck having to do an absolute import like the one I presented above.


*Right now, as far as I can tell from the PEP you linked, they're only available in a "preview" of sorts by using from __future__ import blah. In other words, it'll become part of the normal, official syntax in Python 2.6, and should generally be ignored until then.

bitprophet
Jul 22, 2004
Taco Defender

Chin Strap posted:

How far off is 2.6? Shouldn't you be writing your code in a way that it is future ready?

What JoeNotCharles said :) Using stuff that's only in __future__ isn't really being "future ready" as much as it's more like gambling.

Truly "future ready" would (in my opinion) be stuff possible in the current syntax that avoids using to-be-deprecated behavior. For example, getting in the habit of using print("foo") instead of print "foo", since IIRC that's how things are moving for Python 3.x.

bitprophet
Jul 22, 2004
Taco Defender

Milde posted:

The two print forms aren't compatible with each other.

...they aren't?
code:
jforcier@sunner ~ $ python
Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print "foo"
foo
>>> print("foo")
foo
>>>
Not snarking -- but I've seen/used both interchangeably without problems, at least on 2.5. What do you mean by "aren't compatible"?

bitprophet
Jul 22, 2004
Taco Defender

Bonus posted:

code:
>>> print('hehe', 'hahaha')
('hehe', 'hahaha')
>>> print 'hehe', 'hahaha'
hehe hahaha
edit: ugh, beaten, gently caress you milde

Hrm, between this and Milde's explanation I guess I'm a noob or something when it comes to printing; I never, ever do print x, y, instead doing either print "%s %s" % (x, y) or print " ".join([x, y]) (obviously for varying numbers of strings, not just two). I also never use the >> operator, instead opting for the more obvious (for me) fileobject.write("foo").

All that aside, I get your point, the semantics are obviously changing in a more complicated way than in my original example, rendering it moot. And I never intended to say that one should not use 2to3 -- you certainly should.

Finally, as has sort of been implied, someone who's new enough that they need to ask about different import styles probably shouldn't seriously worry about futureproofing (not trying to put down Panic!).


Also, speaking of 2.6/3.0, looks like the final betas just came out. Yay :) Wish I was following this stuff more closely, but not using Python 100% of the time in my job has made me slack off a bit.

bitprophet
Jul 22, 2004
Taco Defender

Bozart posted:

I don't know if anyone has mentioned this yet, but http://code.google.com/p/soc/wiki/PythonStyleGuide is pretty useful in terms of both examples and explanations of style. Some people might be annoyed by the two space tab instead of four space tab, but you can always ignore that.

Wonder what reason they have to diverge from the official Python style guide, PEP 8?

bitprophet
Jul 22, 2004
Taco Defender

Bozart posted:

and why it is good to have it (and PEP doesn't mention this at all)
and decorators, which PEP doesn't mention at all

Yea, PEP8 (note: don't just call it PEP, there's far more than one PEP! :)) could theoretically be extended with more guidelines, although then again given Guido's penchant for keeping stuff simple, maybe not. I'd still like to see it updated or another PEP added as an addendum with "extra guidelines".

You know, trying to document what it means to be "Pythonic", sorta like that site I probably have bookmarked but can't find right now (guy has a nice big list of Python idioms and what to do / not do).

bitprophet
Jul 22, 2004
Taco Defender
Yea, that Goodger link was it, much thanks (looks like he's updated the layout a little bit since I last saw it though, but in a good way).

bitprophet
Jul 22, 2004
Taco Defender
Bonus is correct, but you should know that the general compsci term for this is "mapping", usually in the form of a map() function. The idea being that you "map" some other function onto your list so that the list is modified in place.

Python has map(), but it's considered more Pythonic to use a generator expression (you'll often see list comprehensions which are nearly identical, more common, but actually less preferable) as Bonus showed just above.

bitprophet
Jul 22, 2004
Taco Defender

Moof Strydar posted:

Nice, I haven't used generators much. However, I didn't explain myself properly (or at all, really): I'm trying to make a "Find next" dialog, which searches from the currently selected item in a list control, so I only want to find the index of the next instance of the value, not all the values.

I think the way I've written it, the generator would end up searching from the start of the list and skipping everything generated until after the given starting index...

Anyway, I realized I can use something along the lines of boring old C-style 'for' loops. I'm a colossal dunderhead tonight. :shobon:

Read up on Python iterators/iteration, specifically the next() method, or manual generators and the yield statement. In other words, you can get the same benefits as a generator expression, but without doing it all at once, instead calling next/yield when your code needs the next item.

bitprophet
Jul 22, 2004
Taco Defender

duck monster posted:

Grab a copy of Django and gently caress around with that.

Not a bad idea (as long as you use the built-in "runserver" -- unless you're already a web dev, don't get bogged down with installing Apache or anything), doing the Django tutorial and then making a simple site will expose you to a lot of real-world Python very quickly :)

bitprophet
Jul 22, 2004
Taco Defender
See, I just DO NOT GET why everyone has this huge stiffie for developing (sans runserver and the builtin Python, of course -- which is fine for a newbie) on a local OS X workstation. It's loving retarded -- you have to wrestle with 3 or 4 different potential methods of installing the various components and then you end up with 2 versions of just about everything (the Apple default and the new one you installed because the Apple default is too loving old or lovely).

I do all my dev on standalone Linux servers, or VMWare Fusion running the same. aptitude install libapache2-mod-python python-psycopg2 postgresql-server and those (and their automatically installed dependencies) get me 95% of the way there, no fuss, no muss. An svn checkout of Django and I'm pretty much all done.

Just kills me that people put so much effort into Mac-native dev; my office is largely a Rails shop and they do the same thing, drives me bonkers.

/derail

bitprophet fucked around with this message at 00:27 on Sep 29, 2008

bitprophet
Jul 22, 2004
Taco Defender

duck monster posted:

Because I have a mac in front of me , and not a linux or windows box. v:shobon:v

THAT'S NO EXCU--wait, maybe it is :( My condolences. I do seriously recommend VMWare Fusion, though -- if you've got the RAM to do local web development, you've got the ram to drop 256-512 megs in a Linux VM. It's so much nicer...

Sorry to hear about your psycopg2 woes, I don't think I've ever actually set that up on OS X myself so I can't offer any advice. I tend to use Macports for everything that I do need locally, though (generally shell related stuff for non-Web Python scripting, vim, wireshark, etc) and it's always worked pretty well. Not sure why it didn't work out in your case.

bitprophet
Jul 22, 2004
Taco Defender

m0nk3yz posted:

IANAWU (I am not a windows user) - but during the 2.6 release process, I had some multiprocessing bugs that came up on windows I needed to break the vmware out for. I can not even begin to image the pain of regular windows users when it comes to the windows build process. I eventually gave up, winged the patch and deleted the VM. Also, gently caress mingw.

I tend to roll my eyes whenever David Hanssen (the Rails guy) speaks, but he said something relatively fitting a couple years ago, something about how "web developers who continue choosing to develop primarily on Windows will become increasingly marginalized", and I think that sentiment can be extended generally (not just Web development).

Unix (and by extension OS X, system framework problems aside) is just such a better development environment in almost every fashion. It's a real shame Microsoft had to do their own thing back when they started DOS/Windows; I'm imagining a world where they did what Apple did circa 2001, and took Unix and put their own stuff on top of it. It'd be a very different climate, I feel (although I doubt they'd approach it quite the same way Apple did).

/derail

bitprophet
Jul 22, 2004
Taco Defender

tef posted:

Lets all run Xenix and AUX

I hope you're just being silly and aren't missing the fact that I'm alluding to OS X :) A/UX is a cute historical footnote but isn't what I was going for.

bitprophet
Jul 22, 2004
Taco Defender

tef posted:

I guess what I'm trying to say that both companies have dabbled in unix before.

Right, but Apple has actually gone a very long ways with it now and made a very compelling OS with the idea; Microsoft hasn't. Anyway...this is no longer Python related, so I'll shut up now :)

bitprophet
Jul 22, 2004
Taco Defender
Congrats m0nk3yz (and the rest of the core team obviously)! :toot:

I wish I was more excited, though; I'm not even making use of everything new in 2.5, and it feels like only yesterday that 2.5 even became widely available in package managers, versus 2.4. So it's not like I'll realistically be able to make use of 2.6 in a "run on something that's not my personal workstation" capacity for goodness knows how long :(

Still! The road to 3.0...

bitprophet
Jul 22, 2004
Taco Defender

deimos posted:

While I agree, 2.5 does have basically one of the better things of 2.6 which is context managers. Also 2.6 starts moving towards more PEP8 compatibility and the new print() which is always a good thing. 2.6 is more of a revision IMHO but a good solid step forward.

That's true, a few of the 2.6 stuff leaked into 2.5, didn't it...and yes, I'm well aware that 2.6 is largely a stepping-stone release to help folks get onto 3.0, but I still won't be able to do stuff like aforementioned new print() until I can expect to use 2.6 everywhere. Poop.


Ironically...this may matter less as I find myself moving at least partially into the Ruby/Rails camp, due to my job (Rails and PHP shop, and christ do I hate PHP, and sadly can't spend 100% of my time doing my sysadmin duties). Speaking of which, I plan to "open up" a blog (don't have one yet) with a series of posts comparing -- at a realistic, daily-usage level -- the two ecosystems (Ruby/Rails vs Python/Django).

I haven't seen anything else at this level, just high level overviews, which makes sense -- I expect very few people would ever be in my situation, being well versed in one framework but essentially "forced" to become fluent in another. Most people will get good at one and then stick with it due to simple inertia if nothing else.

Anyone find that idea interesting? Wonder if it would make sense to do it as a thread here instead -- I definitely plan to get feedback, somehow, from both sides, as I expect to miss or misunderstand some stuff :)

bitprophet
Jul 22, 2004
Taco Defender
Macports' version not working? (I forget if we went over this already in the Django thread :v:)

bitprophet
Jul 22, 2004
Taco Defender

LuckySevens posted:

[st]Newb question, whats the logic behind if __name__ == '__main__'? It seems like some kind of way to test code but I can't quite work it out :([/st]

cancel that, I've worked it out!

Protip: never just say "nm I got it!" -- explain what you found / how you solved your problem! Otherwise another newb finding your question on Google or whatever, and not seeing an actual answer, is going to hate your guts :)

bitprophet
Jul 22, 2004
Taco Defender

Colorblind Pilot posted:

Let's say I have a function and variable defined like this

code:
def this_is_a_test():
  print "LOL!"

x = "is_a_test"
Is there any way to call my function by calling "this_" + x()

basically dynamically constructing the name of my function based on the variable x? I know it can be done in Ruby, but it would make my life a lot easier if Python could do it too.

It can be done, but that sort of "clever" programming is generally discouraged because it makes for difficult to debug / understand code (not to mention making bugs a lot more likely).

Offhand I'd do it like this:
code:
def this_is_a_test():
    print "LOL!"
x = "is_a_test"
locals()['this_' + x]()
since locals() returns a mapping of the local namespace.

EDIT: Like the below post, I'd say a more transparent and less problem-prone approach would be to explicitly organize the methods in a dict or other data structure, since it's easy to toss around functions as objects.

bitprophet fucked around with this message at 04:02 on Oct 23, 2008

bitprophet
Jul 22, 2004
Taco Defender

Bonus posted:

Yeah, I prefer an OOP/functional combination as well. And when I mean OOP, I don't mean Java-style OOP where your program is basically a big inheritance tree, I just mean taking advantage of the fact that everything is an object but avoiding too much inheritance.

Python-style OOP is definitely the better way to think about the paradigm, IMHO. It's simple enough to understand and use, and extremely powerful/flexible, without going overboard "just because OOP > *" like Java seems to. That's really Python in a nutshell, to me: everything you need, nothing you don't.

I'm still enjoying learning Ruby and Rails, but the more Ruby I learn the more I <3 Python. For example, in Ruby, attempting to reference a "normal" variable (e.g. foo) that doesn't exist, will throw an exception, as you'd expect. However! Attempting to reference an instance variable (e.g. @foo) that doesn't exist, will silently act as if it were nil (None).

So, incredibly hard to diagnose bugs ("Goddammit, why is this thing nil?! I know I assigned to it right here and my print statement shows it plain as day!!") become a simple one-character typo/mistake away. :waycool: Reminds me of PHP and its tendency to swallow errors whole. Friggin' sigils....Ruby's about 1/2 Perl, and based on that I have to say Perl is a poor role model :eng99:

Anyway, all that to say that this sort of thing helps me understand Guido's emphasis on keeping the language as spare as possible.

bitprophet
Jul 22, 2004
Taco Defender
Sorry if you did get this already, The CRAIGGERS, but Python's pass-by-value/reference is sort of funky: it's actually all about mutability. (At least, in my understanding...)

So, for example, strings are immutable; you can never operate on a string and change it, you can only get back a copy of the string with the change applied. So if you pass a string into a function, it's effectively pass by value, because you can't actually "do" anything to the string that will have an effect in the calling scope.

Lists are mutable; if you update a list member, you're changing the actual list, and not a copy of it. Thus, if you pass a list into a function, it's effectively pass by reference. Modifying the list inside the function will thus be seen in the calling scope after the function returns (because both names are references to the same object in memory).


About the module scope deal, JoeNotCharles is totally right, what you're asking for would be very un-Pythonic Python (if it were actually possible, which it is not AFAIK). Python tries to be clean and explicit and encourage good behavior (while still generally staying out of your way, it's no Java or anything) so generally its language rules try to keep some level of sanity.

Note that you can read all of Python's rules in the docs, and as a C coder most of the terminology should be old hat to you (as Python is written in C itself, the core team tends to write for an audience that might also know C or similar languages). The language reference might help.

bitprophet
Jul 22, 2004
Taco Defender
What he said. Abstract classes and interfaces are just baggage a language can use to add extra layers of safety, at the cost of development time and probably execution/compile time too. In languages like Java/C++, which fall towards the safety end of the spectrum, they're a useful tool because that's the mindset you're working in.

But in Python and other "agile" languages, which take the other side of the tradeoff (trust your coders to do things the right way and don't tie them down with as many rules) such things are generally frowned upon because, again, that's just not how you write Python, and it adds unnecessary time/effort to your development.

A couple of high profile projects such as Twisted and Trac make heavy use of Java-isms like interfaces, and -- surprise, surprise -- they can be a pain in the rear end to work with and certainly do not feel like real Python code much of the time.

If you're dead set on using such tools in Python (again, we recommend you just use duck typing -- implement the actual methods of the interface, but don't bother coming up with a way to enforce/advertise it) the library that seems to be used the most is a Zope originated one called zc.Interface, I think. Look at the programmer's guides for Twisted or Trac and they should mention it early on.

bitprophet fucked around with this message at 23:55 on Nov 5, 2008

bitprophet
Jul 22, 2004
Taco Defender

BigRedDot posted:

We did this at the python shop I worked at and frankly I am appalled that anyone would think that doing so is a bad idea or "unpythonic". Python just by its nature demands more diligence with documentation, especially for very large collaborative projects (such as we developed).

Right, and if you're using the NotImplementedError bit as documentation, that's fine (especially if the superclass is its own class and isn't an empty abstract class, IMO) -- and other folks might choose to only use literal text documentation saying "ok we have this type of API that classes can implement".

It's the thought that you must have fully abstract interfaces in order to Get Stuff Done that's un-Pythonic, in my opinion.

bitprophet
Jul 22, 2004
Taco Defender

Id4ever posted:

Which of the following is the most pythonic way of checking that an object isn't None:

a) if x:

b) if not x is None:

c) if x is not None:

I think I've seen all of these in the wild. I prefer the first one, but when I see pros like Mark Summerfield use c) I wonder if there's a good reason to avoid a).

First off, anyone using b) is silly since c) says the same thing but is more readable :) IMHO.

Secondly, a) is perfectly acceptable in most cases, but is simply less explicit / accurate than c). It's the same reason that databases have NULL as well as boolean False: sometimes False is an acceptable "good" value, whereas in the same scenario the "empty value" -- None -- would be "bad".

bitprophet
Jul 22, 2004
Taco Defender

BigRedDot posted:

Probably because they (unlike you?) do lots of productive work with it.

I think he was being sarcastic (given that he's not the person Habnabit was responding to)? Hope so, anyway.

bitprophet
Jul 22, 2004
Taco Defender

m0nk3yz posted:

Slightly on topic: anyone else going to PyWorks this week in atlanta?

I'm not! :D Hope it's a good con though.

Speaking of cons, I'm starting to think I may not be able to make it to PyCon next year either. Was hoping to attend, especially since I've got some pressure to help push the book, but I really doubt I can spare the money for the travel/board/fees (my wife is chronically unemployed due to the poor animation market, so that makes our financial situation not the greatest).

Almost makes me miss my last job; they paid for yearly training, including conferences and such.

vvv Reeeeallly....I'll have to look into that. Thanks for the tip, I had no idea they'd actually help people go to the cons, given that your average tech worker is usually well off. EDIT v2: and, also, if I'm lucky I might make a little money off the book by then, we'll have to see :ninja:

bitprophet fucked around with this message at 19:00 on Nov 12, 2008

bitprophet
Jul 22, 2004
Taco Defender

chemosh6969 posted:

It at would last until the screen closes down at the end of the job which means I wouldn't see it anyway.

We don't care about your particular use case here. We're just trying to point out that what you're doing is the Python equivalent of e.g. PHP's mysql_query("UPDATE table SET field='" . $_GET['raw_user_input'] . "'");. Yea, sure, "it works for now", but it's dumb to the point of retardation, and is an absolutely horrible habit to get into.

You don't (or won't forever, if you do now) work in total isolation, so learning best practices and conventions is the best way to ensure you won't run into problems working with other folks, using other peoples' code, and so forth.

Or, say, trying to help out other programmers on a coding forum on the Internet, where you're passing on this really bad habit to newbies. That's why the PHP ecosystem is such poo poo -- this sort of thing, people passing bad information around until it becomes conventional wisdom.

bitprophet
Jul 22, 2004
Taco Defender

The Remote Viewer posted:

How long will it take me to get to the point where I can create a very basic roguelike in Python, with some minor past experience in programming?

It's kind of hard to give any sort of real estimate, it's like asking "how long till I get my black belt?" in a martial art -- it's different for everyone.

That said, Python should be quicker than almost any other language, given its syntax (easy and powerful) and the available libraries (core and third-party).

For example, I'm sure there are curses libraries out there (I think there's at least one in the stdlib) which would obviously take a lot of the work out of the actual UI components; depending on how you want to track state, there's a lot of modules for databases (RDBMS or small stuff like SQLite or bdb) and just general persistence (pickling, marshaling etc). And so forth.

Put another way, I'd bet your major hurdles will be understanding the overall concepts involved (screen output / redrawing, handling user input, data structures, keeping state, the concept of data persistence, and so on) and less about the specifics of the code itself.

bitprophet
Jul 22, 2004
Taco Defender

Janin posted:

If you think Python scripts should use #!/usr/bin/env python, do you also code your shell scripts to use #!/usr/bin/env sh?

That's not a fair comparison; any system ever is going to have some shell binary symlinked/installed as /bin/sh, but as others have already explained it's common for Python to be installed in any of a multitude of different locations, not just /usr/bin/python.

bitprophet
Jul 22, 2004
Taco Defender

not a dinosaur posted:

But that subtracts every element in t1 from every element in t2- I want (x[0]-y[0], x[1]-y[1], ...). Is this possible without reverting to for loops?

Pedantry: what you posted is actually a generator expression, not a list comprehension :) List comps have square brackets instead of parentheses. However, generator expressions are generally "better" as they have identical syntax but are usually more efficient -- so keep using them, just make sure you have the terminology right.

Anyway, think about your problem this way: you have two lists, and you want to do an operation on each pair of items, the pair being defined as "the items at the same index", right? I.e. subtract the pair of items at index 0, then index 1, ..., then index N.

You can't do this by iterating over one, then the other, which I think is what your expression does (honestly I've never seen that 'double loop' syntax before...curious). What you want to do is "zip" the two lists up, so you get a list or tuple of two-tuples: [(t1[0], t2[0]), (t1[1], t2[1]), ..., (t1[N], t2[N])].

This is, in fact, called zipping, and is a builtin method(s): http://docs.python.org/library/functions.html#zip (and also izip as in the previous post :argh:)

Thus, I think you want: (x - y for x, y in izip(t1, t2)).

Ninja edit value-add: izip is better than just plain zip, because it itself uses an iterator and is thus more memory efficient if your input lists are large. Also: if len(t1) != len(t2), you'll run into problems unless you figure out what you want the 'padding' values to be, lest you get errors trying to do e.g. 1 - None.

bitprophet fucked around with this message at 15:49 on Nov 21, 2008

bitprophet
Jul 22, 2004
Taco Defender
Call me stupid, but why do you need it explicitly turned into a list given that strings already support indexing, slicing and iteration? :v: (If you didn't know that -- well, they do :))

bitprophet
Jul 22, 2004
Taco Defender
The expression after the 'in' is evaluated only once, and the result is then iterated over (via a call to __iter__, I believe, but that's not important here). This expression is NOT re-evaluated every time, AFAIK.

In the first example, the expression evaluates to 'a', which is the name of a list object. Thus, the for loop iterates over "the object known as 'a'", and since that object keeps changing in the loop body, you get the infinite loop.

In the second example, the expression evaluates to [0,1], because that's what range(len(a)) evaluates to when the loop is first entered. This is NOT a name of a list, but is instead just a list. The fact that it was initially generated based on the length of 'a' doesn't matter, because range(len(a)) was only called one time, in order to get the object-to-iterate-over.

Thus, the second example works normally, because [0,1] never changes -- it's not tied to the value of 'a' in any way.

Hope that made sense...it sounds like you sort-of figured it out in your guess, if I read you correctly.

bitprophet
Jul 22, 2004
Taco Defender

supster posted:

I'm sorry for asking probably previously-answered questions that no one likes to reanswer again... but:

(1) If I'm starting with Python, should I jump into 3.0 or 2.6? How common is it to not be able to find a 3.0 library for a common task that exists for 2.6?

2.6. 3.0 is extremely new and almost nothing has been ported to it yet. 2.6 will include some of the newer libraries/ideas present in 3.0, so you'll be better off for learning 3.0 than someone who's used to older verisons of Python. 3.0 will not be mainstream for at least a year or two (someone like m0nk3yz or king_kilr will have a better estimate, probably).

quote:

(2) What development environments are recommended? Are different IDEs generally used for console applications vs windows applications vs django?

This is totally up to you; many Pythonistas don't even use an IDE in the literal sense of the term (a big all inclusive whizbang thing with a built in browser and terminal and etc). Definitely don't think you'd need different editors for different "types" of Python coding, at any rate. Pick one and use that. I love vim (others emacs); others love TextMate (and it is quite good); some like IDLE or Eclipse-plus-some-Python-plugin; etc.

bitprophet
Jul 22, 2004
Taco Defender

m0nk3yz posted:

I know there was some discussion about contextmanagers earlier in the thread, as an FYI I just put the article from pymag up which gives a lot more information. It's only 2000 words or so, so I shouldn't get yelled at for it being too long. Here.

tl;dr


Seriously though, that was a great article :) makes me wonder if getting the Python Mag is worth it after all. (I assume you get a subscription for free for being a contributor? How is it?)

I also need to work through your other, longer recent reposts sometime; skipped them for now, not really due to the length but due to not caring as much about threading (yet).

bitprophet
Jul 22, 2004
Taco Defender

m0nk3yz posted:

Oh god, I tried to grok twisted. http://jessenoller.com/2009/02/11/twisted-hello-asynchronous-programming/

Sup learning-Twisted buddy :):hf::) Thanks for the article (and especially the links at the end. Delicious, tasty links)! I think it's neat you were talking to Glyph about it, and how that resulted in that peek at the "advanced" usage of the decorator/generator stuff.

Also, I know you tend to complain that users bitch about the length of your articles, but I thought this one was pretty on the mark. Many tutorials/articles are shorter and would basically have been the first half of yours -- a high level overview and 1-2 simple examples. But then you went a bit deeper and gave a good idea of not only what's possible at the basic level, but what lies beyond that. (And it wasn't so long as to get dreary ;))

bitprophet
Jul 22, 2004
Taco Defender

shaitan posted:

ahh, I wasn't thinking of compatibility in that sense. That makes a pretty good argument for sticking with 2.6. Thanks!

The other big reason is that 2.6 has as many of the new features/changes from 3.0 as is possible without actually breaking backwards compat, so it's sort of like 3.0 Lite in that sense.

as opposed to 2.4 or 2.5 which us existing Pythonistas writing software for wide consumption have to support and thus we don't get to play with the new shinies :cry:

bitprophet
Jul 22, 2004
Taco Defender
^^^^ LORD UFFENHAM :argh:

fnordcircle posted:

code:
    new_word=raw_input("Gimme a word: ")

    for i in range(len(new_word)):
        print new_word[i]
        i=i+1

Maybe I'm missing something, since nobody else corrected you on this, but you don't need to do that i=i+1 there. Python for loops iterate over some sort of collection, and thus rarely need any sort of counter variable.

In fact, Python strings are themselves iterable objects (returning single-character strings -- there's no "char" type), so your code can be simply rewritten as:

code:
new_word = raw_input("Gimme a word: ")
for character in new_word:
    print character

Adbot
ADBOT LOVES YOU

bitprophet
Jul 22, 2004
Taco Defender

Grinnblade posted:

if (body.lower.left(self.settings.myname.length()) == self.settings.myname.lower()):
replyrate = 100

missing parens.

wrt your last example, you are slicing incorrectly. "mystring"[0:1] will result in "m"; the right index is exclusive. so "the first 2 chars" would be [:2] (note: zero is not necessary, which is why that example right there will work; nor is end-of-string, you can just do e.g. mystr[5:] to get from the 5th char to end of string)

  • Locked thread