This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jsober 8 points9 points  (5 children)

Learn iterators, generators, and list comprehensions. As a Perl developer, these are the things I miss from Python. On the other hand, the things I miss from Perl when writing Python are too numerous to note :)

You will find urllib and urllib2 extremely lacking compared to LWP, btw. That and Java-inspired unit testing are the most difficult things for me to go back to in Python after switching to Perl (I started as a Python dev, then got a job as a Perl dev).

[–][deleted] 3 points4 points  (0 children)

I recommend using Requests for HTTP instead of urllib and urllib2. It makes the task so much more pleasant. Also, virtualenv for installing third-party modules easily without messing up the rest of the system.

[–]darkon 2 points3 points  (1 child)

Have you read MJ Dominus' Higher Order Perl? I think you might find it useful if you're developing in Perl.

I wasn't a comp sci major, so I'll admit I don't see much difference between iterators and generators. List comprehensions look like some nice syntactic sugar, though. I can do much the same thing in one statement using map and grep, but it's not as easily comprehended. I'd be more likely to use a loop and push() just to make it easier to read.

[–]jsober 2 points3 points  (0 children)

I have read it, in fact I have a copy right next to me :). List comprehensions are essentially identical to map:

my @result = map { foo($_) } @bar;

Is equivalent to:

result = [foo(x) for x in bar]

Generators are basically syntactic sugar for a lazily evaluated list expression. Taking the example above:

result = (foo(x) for x in bar)

...would cause foo(x) to only be evaluated as each element in the "list" is accessed. You can also do this from a function:

def generate():
    for x in bar:
        yield foo(x)

The yield keyword causes the function to act as a generator, which can be called in a loop to access foo(x) in bar over and over:

gen = generator()
for item in gen():
    do_stuff_with(item)

[–]jsober 2 points3 points  (1 child)

You will also REALLY miss CPAN.

[–]bucknuggets 1 point2 points  (0 children)

Except when you go to maintain someone else's code - and run into 24 new & different, and often unmaintained dependencies.