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
Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug
This idiom is in the Python documentation, and though I've only used it a few times, I was always impressed by its elegance:

code:
In [1]: items = range(20)

In [2]: list(zip(*[iter(items)] * 4))
Out[2]: 
[(0, 1, 2, 3),
 (4, 5, 6, 7),
 (8, 9, 10, 11),
 (12, 13, 14, 15),
 (16, 17, 18, 19)]

In [3]: list(zip(*[iter(items)] * 5))
Out[3]: [(0, 1, 2, 3, 4), (5, 6, 7, 8, 9), (10, 11, 12, 13, 14), (15, 16, 17, 18, 19)]

Adbot
ADBOT LOVES YOU

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Lysidas posted:

This idiom is in the Python documentation, and though I've only used it a few times, I was always impressed by its elegance:

code:
In [1]: items = range(20)

In [2]: list(zip(*[iter(items)] * 4))
Out[2]: 
[(0, 1, 2, 3),
 (4, 5, 6, 7),
 (8, 9, 10, 11),
 (12, 13, 14, 15),
 (16, 17, 18, 19)]

In [3]: list(zip(*[iter(items)] * 5))
Out[3]: [(0, 1, 2, 3, 4), (5, 6, 7, 8, 9), (10, 11, 12, 13, 14), (15, 16, 17, 18, 19)]

Good luck figuring out how it works! It relies on several tricky things, so I don't recommend using it.

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug

Suspicious Dish posted:

Good luck figuring out how it works! It relies on several tricky things, so I don't recommend using it.

Yeah, it can be overwhelming for someone who's new to Python. This is the key to understanding what's going on:

code:
In [4]: [iter(items)] * 4
Out[4]: 
[<builtins.range_iterator at 0x162a510>,
 <builtins.range_iterator at 0x162a510>,
 <builtins.range_iterator at 0x162a510>,
 <builtins.range_iterator at 0x162a510>]
There's a single iterator object, and every time you call next on it you of course affect the duplicate references to that iterator. zip gets elements in order, advancing the iterator by 1 each time.

JetsGuy
Sep 17, 2003

science + hockey
=
LASER SKATES

tef posted:

munctional programming!

code:

>>> fjords
[1, 18, 17, 15, 10, 14, 0, 6, 8, 19, 9, 5, 13, 2, 16, 4, 12, 11, 7, 3]
>>> for a,b in zip(fjords, fjords[1:]):
...     print a,b
... 
1 18
18 17
17 15
15 10
10 14
14 0
0 6
6 8
8 19
19 9
9 5
5 13
13 2
2 16
16 4
4 12
12 11
11 7
7 3
>>> 

Why doesn't zip complain that fjords and fjords[1:] aren't the same size? is it smart an just go to the lowest length?

FoiledAgain
May 6, 2007

JetsGuy posted:

Why doesn't zip complain that fjords and fjords[1:] aren't the same size? is it smart an just go to the lowest length?

The length of the returned list is only as long as the shortest argument.

Scaevolus
Apr 16, 2007

Lysidas posted:

This idiom is in the Python documentation, and though I've only used it a few times, I was always impressed by its elegance:

code:
In [1]: items = range(20)

In [3]: list(zip(*[iter(items)] * 5))
Out[3]: [(0, 1, 2, 3, 4), (5, 6, 7, 8, 9), (10, 11, 12, 13, 14), (15, 16, 17, 18, 19)]
I really wish something equivalent to this was builtin, since I tend to do it a lot.

The usual form I end up with is:
code:
l = range(20)
[l[x:x+5] for x in xrange(0, len(l), 5)]

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Scaevolus posted:

I really wish something equivalent to this was builtin, since I tend to do it a lot.

The usual form I end up with is:
code:
l = range(20)
[l[x:x+5] for x in xrange(0, len(l), 5)]

grouper, in the itertools recipes, is what you want.

blow job lady
Dec 5, 2010

So I'm a total baby when it comes to coding, and I have a program due tomorrow (for a comp. 101 class, just taking it as an aside) involving taking data from a website (using python). I'm having issues figuring out how to use urllib to open and read the data, am continually getting a 'list index out of range' error pertainign to the line i have written as " url = sys.argv[1] ". Again, I'm dumb and in over my head and all that, but can anyone explain to me what the issue is [or should i link the whole program to this point(or should I kill myself)]?

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

Shelflife 2000 posted:

So I'm a total baby when it comes to coding, and I have a program due tomorrow (for a comp. 101 class, just taking it as an aside) involving taking data from a website (using python). I'm having issues figuring out how to use urllib to open and read the data, am continually getting a 'list index out of range' error pertainign to the line i have written as " url = sys.argv[1] ". Again, I'm dumb and in over my head and all that, but can anyone explain to me what the issue is [or should i link the whole program to this point(or should I kill myself)]?
sys.argv is the command line argument list. the first element sys.argv[0] is always the script name.

sys.argv[1] would be the first argument that you are passing to your script.

Presumably if you are getting that error then you are not passing any parameters when you call your script.
code:
python foo.py arg1 arg2 ...

blow job lady
Dec 5, 2010

peepsalot posted:

sys.argv is the command line argument list. the first element sys.argv[0] is always the script name.

sys.argv[1] would be the first argument that you are passing to your script.

Presumably if you are getting that error then you are not passing any parameters when you call your script.
code:
python foo.py arg1 arg2 ...

Thanks, I appreciate it.

Begall
Jul 28, 2008
I'm not really sure this is actually a Python question, but since the language I'm using is Python I figure I can ask it here. As you might be able to tell I'm pretty new to coding, and I've been trying to write a plugin for SiriServerCore part of which is the following expression I'm attempting to match to speech using Regex:

code:
(Watch|Put on) (?P<videotitle>[^^]+) season (?P<seasonnumber>[\d]+) episode (?P<episodenumber>[\d]+)
This works 100% as expected. The issue is I want to be able to match it when the "season # episode #' part is not present. I've tried doing this without success:

code:
(Watch|Put on) (?P<videotitle>[^^]+) (season)? (?P<seasonnumber>[\d]+)? (episode)? (?P<episodenumber>[\d]+)?
Any ideas what I'm doing wrong?

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
The second space probably needs to be in the none or 1 match, so (season )?

The Gripper
Sep 14, 2004
i am winner
Well the second regexp has whitespace between the optional matches, you'll need to move that inside the parenthesis for season and episode (or it will be required). You could also use (?: season ) so that "season" and "episode" aren't added to capture groups, something like:
code:
(Watch|Put on) (?P<videotitle>[^\s]+)(?: season )?(?P<seasonnumber>[\d]+)?(?: episode )?(?P<episodenumber>[\d]+)?


I tested it out here: http://codepad.org/b4yIVTCP though I changed the [^^] (match anything that isn't a caret) to [^\s] (match anything that isn't whitespace). Without doing that the title match could try to match the entire string, including season and episode because with them being optional the videotitle match is greedy. It's obviously not right for titles with spaces in them, but I was too lazy to actually go back and fix it so I'll leave that as an exercise to you!

Edit; I lied, I have some kind of code OCD. Here's one that should work but I still feel like it's a bit convoluted, using atwo lookaheads http://codepad.org/fyIFtZuv. Pretty much matches title as either <any string> followed by "season", or <any string> NOT followed by "season" (which should only be when there is nothing following the title. Or, when the show is called something bogus like "All Seasons", which you're then probably hosed on.)

The Gripper fucked around with this message at 13:03 on Apr 24, 2012

Begall
Jul 28, 2008

The Gripper posted:

Well the second regexp has whitespace between the optional matches, you'll need to move that inside the parenthesis for season and episode (or it will be required). You could also use (?: season ) so that "season" and "episode" aren't added to capture groups, something like:
code:
(Watch|Put on) (?P<videotitle>[^\s]+)(?: season )?(?P<seasonnumber>[\d]+)?(?: episode )?(?P<episodenumber>[\d]+)?


I tested it out here: http://codepad.org/b4yIVTCP though I changed the [^^] (match anything that isn't a caret) to [^\s] (match anything that isn't whitespace). Without doing that the title match could try to match the entire string, including season and episode because with them being optional the videotitle match is greedy. It's obviously not right for titles with spaces in them, but I was too lazy to actually go back and fix it so I'll leave that as an exercise to you!

Edit; I lied, I have some kind of code OCD. Here's one that should work but I still feel like it's a bit convoluted, using atwo lookaheads http://codepad.org/fyIFtZuv. Pretty much matches title as either <any string> followed by "season", or <any string> NOT followed by "season" (which should only be when there is nothing following the title. Or, when the show is called something bogus like "All Seasons", which you're then probably hosed on.)

That's brilliant, thanks! Missing that by not including the whitespaces in the parenthesis I was making them required was pretty :downs: now that you've pointed it out, but I don't think that would ever have occurred to me on my own.

Now to see if I can actually put in the stuff this should enable successfully~

epswing
Nov 4, 2003

Soiled Meat
Is creating a zipfile with shutil.make_archive as useless as I think?

I wrote a simple backup script, zip a directory, and getting

code:
Traceback (most recent call last):
  File "backup.py", line 24, in <module>
    shutil.make_archive(zipfile, 'zip', source_dir)
  File "C:\Python27\lib\shutil.py", line 547, in make_archive
    filename = func(base_name, base_dir, **kwargs)
  File "C:\Python27\lib\shutil.py", line 454, in _make_zipfile
    zip.write(path, path)
  File "C:\Python27\lib\zipfile.py", line 1045, in write
    zinfo = ZipInfo(arcname, date_time)
  File "C:\Python27\lib\zipfile.py", line 295, in __init__
    raise ValueError('ZIP does not support timestamps before 1980')
ValueError: ZIP does not support timestamps before 1980
So shutil.make_archive will just fail without recourse if one day a file with a timestamp < 1980 is in the directory I'm zipping? Meaning any python file that uses shutil.make_archive is a nice little time bomb?

(I'm just going to use tar instead. I'm still mad though.)

Begall
Jul 28, 2008
Ok so on a slightly different project I've decided to try and apply my "skills" to :v::

I'm taking postcodes from a spreadsheet (works ok), putting them into the google geocoding API (works ok!) and trying to convert them into Google Earth-friendly coordinates. This is where I'm coming sort of unstuck. Here are the functions I've written (I'm sure they are horrendously inefficient, but please don't laugh too hard):

code:
def grablonglat(outputtype, postcode):
    longlat = ''
    response = urllib2.urlopen('http://maps.googleapis.com/maps/api/geocode/%s?address=%s&sensor=true' %(string.lower(outputtype), string.lower(postcode)))
    returneddata = json.loads(response.read())
    for s in returneddata['results']:
       longlat = s['geometry']['location']
       return longlat
code:
def convertfunc(originallist):
    for x in originallist:
      if len(x) > 5:
        y = re.sub(" ", "", x)
        x = grablonglat('json', y)
        
The problem is that I'm not sure how to store the changes to the called originallist after this. I can see from inserting print x into the 2nd function that it is successfully finding what I'm looking for, but doing for example:

convertfunc(N)
print N

Leaves me with what I started with. Any ideas?

Edit: Actually nevermind! I wrote a bit more into the 2nd function and it now writes out everything I need into a file, which I can then use as a reference :)

Begall fucked around with this message at 16:47 on Apr 27, 2012

The Gripper
Sep 14, 2004
i am winner

Begall posted:

convertfunc(N)
print N

Leaves me with what I started with. Any ideas?
You're not actually making changes to N in that example.

You could replace convertfunc() with something like:
code:
def convertfunc(originallist):
    for i,v in enumerate(originallist[:]):
      if len(v) > 5:
        y = re.sub(" ", "", v)
        originallist[i] = grablonglat('json', y)
    return originallist
...
N = convertfunc(N)
print N
or without the enumerate+slice:
code:
def convertfunc(originallist):
    newlist=[]
    for x in originallist:
      if len(x) > 5:
        y = re.sub(" ", "", x)
        newlist.append(grablonglat('json', y))
      else:
        newlist.append(x)
    return newlist
...
N = convertfunc(N)
print N
Both are equivalent, the first creates a copy of your list to iterate over, so you can make changes to the original, and the second creates a new list instead. In both cases you need to return the modified list, to replace the original N.

Edit; also I didn't even look at that first function, if it works it works I guess but that's a pretty crazy use of a for loop to return.

The Gripper fucked around with this message at 16:51 on Apr 27, 2012

IAmKale
Jun 7, 2007

やらないか

Fun Shoe
I decided to learn Python to augment my sysadmin skillset so I started working my way through a tutorial. It's obvious that the tutorial was intended for 2.x because it still uses stuff like:
code:
print "This is some text: %s" % ("Line of text")
I've since found out about the new print() and format() commands in 3.x, though, so I've been able to continue through the tutorial using the newer commands where necessary.

Unfortunately I've come across a problem. If I have a function called secret_formula() that returns three values, why does format() not work with a call to the function? For example, this works:
code:
print("We'd have {0} beans, {1} jars, and {2} crates.".format(beans, jars, crates))
But this errors out with "IndexError: tuple index out of range":
code:
print("We'd have {0} beans, {1} jars, and {2} crates.".format(secret_formula(start_point)))

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
When you return three values, you're not really returning three values. You're returning one value called a tuple, that has three things inside of it. Thankfully, you can use a tuple (or a list, or any iterable) to fill in arguments for you, with the * operator:

code:
print("We'd have {0} beans, {1} jars, and {2} crates.".format(*secret_formula(start_point)))

geonetix
Mar 6, 2011


Format expects several arguments, one for every replacement.

If your function returns a tuple with things, put an asterisk in front of it to make format accept it as arguments instead of a tuple. Like:

code:
print("We'd have {0} beans, {1} jars, and {2} crates.".format(*secret_formula(start_point)))
That should work. I think.

edit: well, that's a double post if I ever saw one.

IAmKale
Jun 7, 2007

やらないか

Fun Shoe
Oh, that was simple enough. Out of curiosity, would it be possible to pass a tuple to format() and reference elements in it? Something like this:
code:
print("We'd have {0:0} beans, {0:1} jars, and {0:2} crates.".format(secret_formula(start_point)))
I know that code doesn't work, but something along those lines.

geonetix
Mar 6, 2011


Kind of; you can use dictionaries.

In the old style, you could do this:

code:
>>> print "This is a %(name)s" % {'name': 'variable'}
"This is a variable"
I just tried this, and that works:

code:
>>> print "This is a {name}".format(name='variable')
"This is variable"
So, in essence, if your method returns a dictionary, you could do this:

code:
>>> print "This is a {name}".format(**function())
"This is variable"
The double asterisk makes it named arguments, much like the single asterisk makes it positional arguments, to the function. It might be worth reading the documentation on this if you want to pull even fancier stuff.

After a bit more experimenting I found the following working too, which seems to be closer to what you described:

code:
>>> def function():
...     return (1, 2, 3)
... 
>>> print "test {0[0]} is not {0[1]} or {0[2]}".format(function())
test 1 is not 2 or 3

geonetix fucked around with this message at 21:30 on May 2, 2012

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
I was reading the Flask documentation and thinking of playing with it. But I'm not clear on whether, or how, I can make something run in Flask on my shared hosting. The stuff about making it work with Apache might as well be written in Greek. Besides that I'm pretty sure the most I can do to "configure Apache" is to write a .htaccess file. Can anyone give me some pointers? I'm not used to scripts needing a great deal of configuration before they'll run, because I'm used to PHP.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Contact the host and ask if they have support for Python through mod_wsgi or FastCGI. If they have FastCGI support, you can use flup to turn that into something better. Also, if they have Passenger support for Rails, you can use that with WSGI.

The Gripper
Sep 14, 2004
i am winner

Hammerite posted:

I was reading the Flask documentation and thinking of playing with it. But I'm not clear on whether, or how, I can make something run in Flask on my shared hosting. The stuff about making it work with Apache might as well be written in Greek. Besides that I'm pretty sure the most I can do to "configure Apache" is to write a .htaccess file. Can anyone give me some pointers? I'm not used to scripts needing a great deal of configuration before they'll run, because I'm used to PHP.
If your hosting supports CGI at all you can follow these steps and have it guaranteed to work, by just loading up the CGI handler and invoking your app http://flask.pocoo.org/docs/deploying/cgi/

As long as you can get python+flask installed on your shared hosting it should be fine. I'm not sure exactly how you'd do that if you needed to use virtualenv to get your flask+python setup working, though (which might be necessary depending on how python is set up).

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
CGI deployment will be super slow, as Python's startup time is abysmal.

The Gripper
Sep 14, 2004
i am winner

Suspicious Dish posted:

CGI deployment will be super slow, as Python's startup time is abysmal.
Yeah it won't be optimal, I assumed that since they want to use it on shared hosting for just playing around that the performance trade-off for ease-of-install is probably worth it (but don't use it in production unless you have to).

angrytech
Jun 26, 2009
I'm trying to figure out how I can figure out what services are being advertised using avahi on a network.
I looked at pyzeroconf but it doesn't look like it's been updated in several years and that makes me kind of wary. Is this something that could be done more easily by using dbus somehow?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

angrytech posted:

I'm trying to figure out how I can figure out what services are being advertised using avahi on a network.
I looked at pyzeroconf but it doesn't look like it's been updated in several years and that makes me kind of wary. Is this something that could be done more easily by using dbus somehow?

There's an avahi-gobject library which you should be able to use with introspection. Unfortunately, the packages that seem to be shipped with Fedora have it disabled (I just pinged Lennart to re-enable it). Try:

code:
from gi.repository import Avahi
If that fails, look around to see if you can find a package that ships /usr/share/gir-1.0/Avahi-0.6.gir. If not, then you'll have to use the DBus API, which isn't too difficult.

Captain Capacitor
Jan 21, 2008

The code you say?

Hammerite posted:

I was reading the Flask documentation and thinking of playing with it. But I'm not clear on whether, or how, I can make something run in Flask on my shared hosting. The stuff about making it work with Apache might as well be written in Greek. Besides that I'm pretty sure the most I can do to "configure Apache" is to write a .htaccess file. Can anyone give me some pointers? I'm not used to scripts needing a great deal of configuration before they'll run, because I'm used to PHP.

We had a small flask application that we hosted by making Apache proxy to gunicorn. I know Webfaction has a "just proxy to something custom" hosting option, and I'm told some other hosting companies do as well.

Baby Nanny
Jan 4, 2007
ftw m8.

Hammerite posted:

I was reading the Flask documentation and thinking of playing with it. But I'm not clear on whether, or how, I can make something run in Flask on my shared hosting. The stuff about making it work with Apache might as well be written in Greek. Besides that I'm pretty sure the most I can do to "configure Apache" is to write a .htaccess file. Can anyone give me some pointers? I'm not used to scripts needing a great deal of configuration before they'll run, because I'm used to PHP.

You can always use something like http://heroku.com/ and host your static files (CSS, images, etc) on your shared hosting. Heroku is a great (and free!) way to get your python webapps on the Internet when you're learning.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Baby Nanny posted:

You can always use something like http://heroku.com/ and host your static files (CSS, images, etc) on your shared hosting. Heroku is a great (and free!) way to get your python webapps on the Internet when you're learning.

I think I would rather plump for a vps than tie myself in to using something like that.

I checked with my hosting provider and it doesn't look like they are able to support WSGI setups such as are required by Flask and the like.

I'll have to put this idea on the back burner. Thanks for the suggestions.

Baby Nanny
Jan 4, 2007
ftw m8.

Hammerite posted:

I think I would rather plump for a vps than tie myself in to using something like that.

I checked with my hosting provider and it doesn't look like they are able to support WSGI setups such as are required by Flask and the like.

I'll have to put this idea on the back burner. Thanks for the suggestions.

You wouldn't be tied to anything since it'll be using the same git repo that you can just deploy on to a real server or vps when you're ready. Honestly if you're just learning go with heroku there's really no downside (that is until your site gets popular then you just move it)

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Baby Nanny posted:

You wouldn't be tied to anything since it'll be using the same git repo that you can just deploy on to a real server or vps when you're ready. Honestly if you're just learning go with heroku there's really no downside (that is until your site gets popular then you just move it)

Well maybe I should explain my situation. I have a web application that already exists, written using PHP and MySQL. I first opened it up a little over 3 years ago. It has a small but respectable number of users, mostly as a result of doing something that's not available elsewhere (play an obscure boardgame). Some parts of it I'm reasonably proud of, some parts are grotty because I was learning as I went and/or stupid.

I would like to do a better job of maintaining and upgrading it, but I have a couple of problems. I feel like if I invest time into programming as a hobby, it would be a good idea to not stay in my comfort zone all the time with a language I am already familiar with, hence the interest in learning something other than PHP. And also, PHP as a language has its share of problems. For the most part these can be worked around, yes I know PHP makes it easy to write spaghetti code and there are a million array_* functions that all do variations on the same thing and have arguments in different orders, and there is no built-in support for unicode, but all of those things can be carefully navigated if you are familiar with the language and mindful of its shortcomings. But the thing that most motivates a move away from it I think is that the development team seems kind of unserious about producing a language that does a good job and does it securely. For example the recent thing about being able to pass command-line arguments to PHP, admittedly on an uncommon configuration. That was introduced as a regression because the PHP devs noticed their code that guarded against it, said "Was there ever a reason we had this code? Whatever" and deleted it. At the moment my hosting provider takes responsibility for keeping the server's PHP up-to-date, but if I ever chose to move to a VPS for unrelated reasons then I'd have to stay on top of it (I guess) and it sounds like it would be more of a hassle than it would need to be. In contrast to PHP's other flaws, that isn't something that there exists an easy workaround for.

So I toy with the idea of rewriting the thing in another language. This would mean I learn another language and move away from PHP, at the cost of significant duplication of effort.

The real reason I have no interest in Heroku is that if I did re-implement my existing web application in Python, and close the old one and tell everyone to move to te new one, there would be no smooth curve from zero uptake to "too much uptake to be free on Heroku". It would go straight there. Hence no point in Heroku unless I do intend to pay for it. (A 5mb database is no good.)

What I really find myself wondering is why there is no language that has the advantages of PHP without the brain damage. When I say advantages, I mean that you can write a script whatever.php and upload it, and it works straight away. And if you change something and upload it, the new version works straight away, too, you don't need to tell something at the server "pay attention, I changed something", as you apparently do with everything else.

I have no formal education in computer science or software development. By the way what is a good book for picking up Python if you are already familiar with PHP?

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
I'm still rough, but I've learned my Python through:

https://www.diveintopython.net - Python Beginner Book
http://www.amazon.com/Python-Essential-Reference-4th-Edition/dp/0672329786/ - Python Essential Reference (this is a good, concise, 'exactly how does this bit work' reference with minimal fluff, probably would be right up your alley with existing programming experience)
https://www.djangoproject.com - A full stack framework that is a really good beginner gateway to Python Web Applications
https://www.djangobook.com - Developer written book on Django, sometimes out of date, some inaccuracies, but helped me muddle through certain ideas and ways of doing things.

Mileage may vary, but my experience was going from hacking Drupal sites, occasionally doing some PHP work to modify templates or stuff. Learning how to properly passably program in Python was a breath of fresh air from hacking with all that junk.

Maluco Marinero fucked around with this message at 13:24 on May 8, 2012

Baby Nanny
Jan 4, 2007
ftw m8.

Hammerite posted:

...

What I really find myself wondering is why there is no language that has the advantages of PHP without the brain damage. When I say advantages, I mean that you can write a script whatever.php and upload it, and it works straight away. And if you change something and upload it, the new version works straight away, too, you don't need to tell something at the server "pay attention, I changed something", as you apparently do with everything else.

...

It is though the issue is that shared hosters haven't adopted non php setups other than running crap via cgi. With flask/django properly set up you can easily edit a file and upload it and see your changes. I do this all the time with my django sites and both flasks and djangos default dev server support auto reloading on file change. It may seem like a pita at first setting it all up but that's probaly due to a lack of server experience too which is always a good thing to get the basics down of if you're making any sort of website/program.

As for python learning resources definitely check out Djangos tutorial. I've heard good things about http://learnpythonthehardway.com/ too. The best way to learn though is just start writing code and making dumb useless programs.

Also if you're looking for a vps check out linode. I use em for a bunch of sites and have had no problems

SlightlyMadman
Jan 14, 2005

Django runs great on Dreamhost without much trouble. You could also just spin up a micro Amazon EC2 image and set it up there for free or close to it.

Haystack
Jan 23, 2005





Hammerite posted:

I have no formal education in computer science or software development. By the way what is a good book for picking up Python if you are already familiar with PHP?

Python's official tutorial is very well written and a natural point of introduction to the language.

This blog post is a good (and recent) overview of the steps and components involved in writing a web application in python.

epswing
Nov 4, 2003

Soiled Meat
I have a couple Django sites running on Linode, and they have excellent step by step tutorials for Django and practically everything else too. I'm no server admin but I managed to set up apache, postgres, and django without much trouble, just following their tutorials.

Adbot
ADBOT LOVES YOU

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
Yeah, I've got a linode for the software service I'm starting up and it is quite a decent introduction into running your own server. You get root access and you can really choose what and how you'll handle page service, version control, uploading and automation of tasks.

  • Locked thread