Warning

 

Close
Confirm Action

Are you sure you wish to do this?

Cancel Confirm
AR15.COM
11/2/2009 5:06:03 PM EDT
Does anybody here know Python?

I'm trying to teach myself Python with the first thing that i want to program is something small that will use a REST interface to pull down a JSON file and parse it. I'm just not able to wrap my head around this.  I'm trying to pull myself into the 21st century since right now I program in VBScript and that scares my co-workers.

Please help
11/2/2009 5:22:58 PM EDT
[#1]
Python = WIN

11/2/2009 5:26:04 PM EDT
[#2]
I learned how with this book:

http://www.amazon.com/Python-Programming-Absolute-Beginner-Michael/dp/1592000738

I am not familiar with what you are trying to accomplish, but I have been able to find out how to do most anything with Python by Googling for info.
11/2/2009 5:44:20 PM EDT
[#3]
Thanks guys.  I decided to play with PHP for now.  At least it is more current than VBScript.  I should order that book though.
11/28/2009 3:50:31 PM EDT
[#4]
I'd recommend "Learning Python", by Oreilly.  It's written by Mark Lutz, who I've actually taken the "Learning Python" course from, and I'd say it's well worth it.
11/28/2009 4:19:52 PM EDT
[#5]


I would recommend Ruby and Rails. YMMV.

eta: A ruby programming guide is available here: http://www.ruby-doc.org/docs/ProgrammingRuby/
11/28/2009 10:46:43 PM EDT
[#6]
Quoted:
I'd recommend "Learning Python", by Oreilly.  It's written by Mark Lutz, who I've actually taken the "Learning Python" course from, and I'd say it's well worth it.


+1 A very good book.

As for pulling down info from a website (REST doesn't matter much, you're just getting some data) I'd use urllib2 and simplejson modules.

Are you on a windows box or Linux? Its easiest if you have setuptools installed, then you can just easy_install the simplejson module.

This is with python2.6 (which has a json module included):


#!/usr/bin/env python2.6
"""
Get some JSON data from a URL passed on the commandline

Public Domain
"""
import urllib2
import json
import sys


def getJSONPage( url ):
   """
   Get the JSON response from a url
   """
   data = urllib2.urlopen(url).read()
   
   return json.loads(data)


if __name__ == '__main__':
   if len(sys.argv) > 1:
       for url in sys.argv[1:]:
           print "FROM: %s" % (url)
           print getJSONPage(url)
   else:
       print "Usage: %s <URL>" % (sys.argv[0])


Which looks like crap when passed through arfcom's filter –– it strips out all the indenting (4 spaces) which is essential for the program to work.

Here's a paste.org of the code, nicely indented and highlighted.

If you have any questions, just ask. I hate to see people fall down the PHP rabbit hole
11/29/2009 1:00:28 PM EDT
[#7]
Thank you.

The 'real' programmers at work hate that I've fallen to PHP.  I tell them that at least I'm not doing VBScript any longer.

-Mike
11/29/2009 1:11:56 PM EDT
[#8]
People with brain damage, like me, use PERL.


-Foxxz
11/29/2009 6:04:29 PM EDT
[#9]
Quoted:
http://home.gci.net/~johns/new_build.jpg

I would recommend Ruby and Rails. YMMV.

eta: A ruby programming guide is available here: http://www.ruby-doc.org/docs/ProgrammingRuby/


+1 - Ruby is a great "modern" language and Rails is a fantastic web application framework.
11/29/2009 6:20:09 PM EDT
[#10]
Quoted:
People with brain damage, like me, use PERL.


-Foxxz


There is a recovery program for that. I too used to suffer from Perl.
11/29/2009 6:24:54 PM EDT
[#11]
Quoted:
Quoted:
People with brain damage, like me, use PERL.


-Foxxz


There is a recovery program for that. I too used to suffer from Perl.


Suffer? What are you talking about? I love being mental! I'm off to play tetris!



#!/usr/bin/perl

$_='A=15; B=30; select(stdin); $|=1; select(stdout);$|=1; system
"stty -echo -icanon eol \001"; for C(split(/\s/,"010.010.010.010
77.77 022.020.020 330.030.030 440.044.000 055.550.000 666.060.".
"000")){D=0;for E(split(/\./,C)){F=0;for G(split("",E)){C[P][F++
][D]=G} D++}J[P]=F; I[P++] =D}%L=split(/ /,"m _".chr(72)." c 2".
chr(74)." a _m");sub a{for K(split(/ /,shift)){(K,L)=split(/=/,K
);K=L{K};K=~s/_/L/; printf "%c[K",27}}sub u{a("a=40");for D(0..B
-1){for F(0..A-1){M=G[F][D];if(R[F][D]!=M) {R[F][D]=M;a("m"."=".
(5+D).";".(F*2+5)); a("a=".(40+M).";" .(30+M));print " "x2}}}a(
"m=0;0 a=37;40")}sub r{(N)=@_;while(N––) {Q=W;W=O=H;H=Q;for F( 0
..Q-1){for D(0..O-1) {Q[F][D]=K[F][D]}}for F(0..O-1){for D(0..Q-
1){K[F][D]= Q[Q-D-1][F]}}}}sub l{for F(0..W-1){for D(0..H-1){(K[
F][D]&& ((G[X+F][Y+D])|| (X+F<0)||(X+F>=A)|| (Y+D>=B)))&& return
0}}1}sub p{for F(0..W-1){for D(0..H-1){(K[F][D]>0)&&(G[X+F][Y+D]
=K[F][D]) }}1}sub o{for F(0..W-1){for D(0..H-1){(K[F][D]>0)&&(G[
X+F][ Y+D]=0)}}}sub n{C=int(rand(P)) ;W=J[C];H=I[C];X=int(A/2)-1
;Y=0;for F(0..W-1){for D(0..H-1){K[F][D]= C[C][F][D]}}r(int(rand
(4)));l&&p}sub c{d:for(D=B;D>=0;D––){for F(0..A-1){G[F][D]||next
d}for(D2=D;D2>=0; D2––){for F(0..A-1){G[F][D2]= (D2>1)?G[F][D2-1
]:0; }}u;}}a ("m=0;0 a=0;37;40 c");print "\n\n".4x" "." "x(A-4).
"perltris\n".(" "x4)."––"xA."\n".((" "x3)."|"." "x(A*2)."|\n")xB
.(" "x4). "––"xA."\n";n;for(;;) {u;R=chr(1); (S,T)=select(R,U,V,
0.01);if(S) {Z=getc;}else {if($e++>20){Z=" ";$e=0;}else{next;} }
if(Z eq "k"){o;r(1);l||r(3);p}; if(Z eq "j"){o;X––;l||X++;p}; if
(Z eq "l"){o;X++;l||X––;p};if(Z eq " "){o;Y++;(E=l)||Y––;p;E|| c
|c|c|c|c|n||goto g;};if(Z eq "q"){last;}}g: a("a=0 m=".(B+8).";0
" ); system "stty sane"; '; s/([A-Z])/\$$1/g; s/\%\$/\%/g; eval;



-Foxxz
11/29/2009 10:40:04 PM EDT
[#12]




Quoted:



Quoted:

People with brain damage, like me, use PERL.






-Foxxz




There is a recovery program for that. I too used to suffer from Perl.
Same here.  Wrote Perl code for the last 5 years, started Python - have never gone back to Perl - other than to rewrite what I previously did in Perl.