Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Python Parsin

Name: Anonymous 2012-01-30 6:54

Hey /prog/, How can I make this code look cleaner?

Code:        http://pastebin.com/YetPiWJa
Input:       http://pastebin.com/h8BgFYge
NEMA format: http://www.gpsinformation.org/dale/nmea.htm#nmea

Would censor out my info, but fuck it.

Name: Anonymous 2012-01-30 7:01

Python
Found your first problem. Write it in C.

Name: Anonymous 2012-01-30 8:19

>Implying it wouldn't look even worse

I actually just moved from C to Python after 3 years of C, and am loving Python. That being said it does have its downfalls but it allows me to write cleaner, easier understood and powerful code.

Name: Anonymous 2012-01-30 8:25

>>3
clean, easier understood
Sure if you think FORCED INDENTATION OF CODE is good

powerful code
1/10

Name: Anonymous 2012-01-30 9:10

Something like this?
import sys
gpsFormat = lambda x, y: (lambda z: '%s.%s.%s%s' % (z[0][:-2], z[0][-2:], z[1], y))(x.split('.'))
if __name__ == "__main__":
    for line in (l2 for l2 in (l.split(',') for l in sys.stdin) if l2[0] == '$GPGLL'):
        print 'Lat: %s Long %s' % (gpsFormat(*line[1:3]), gpsFormat(*line[3:5]))

Name: Anonymous 2012-01-30 9:11

>>4
I personally believe that forcing users to stick with one single style over the enirety of the language is a good thing. I programmed in C for three years, until I found the Linux Kernel Style my code was absolute C soup and unintelligble to most programmers at a glance. Forcing a consistent style on the user makes code readable across the entire language. I can go look at any other snippet of Python and read the code for what it is rather then "What the fuck is the scope on this line?". Fucking Beautiful.

And about powerful, I can generally write anything (for any nontrivial example) in 10%-25% the amount of code a C varient and still maintain clairity.

And hell, if you wankers still want to write C and harness the awesomeness of python you can do it by writing a simple module. Python is fucking boss like that.

Come at me bro.

(In other unrelated news, why the fuck does Dillo work so well over SSH compared to Firefox/Chromium?)

Name: Anonymous 2012-01-30 9:49

>>6
You wrote shitty code that you couldn't even read yourself when looking back at it and thus you think C is ab unreadable heap of shit.   Go back to your toy programs that no one gives a fuck about you toilet scrubber

Name: Anonymous 2012-01-30 10:09


def gpsFormat (position, waypoint):
    array = position.split (".")
    r = range(4)

    r[0] = array[0][:-2]
    r[1] = array[0][-2:]
    r[2] = array[1]
    r[3] = waypoint

    return "%s.%s.%s%s" % (r[0],r[1],r[2],r[3])
 
if __name__ == "__main__":
    while True:
        #Define a placeholder for the data
        li = ""

        #Get input break at EOF
        try:
            li = raw_input ()
        except EOFError:
            exit ()

        #Seperate, format, print
        li = li.split (",")
        if li[0] == "$GPGLL":
            print "Lat: %s Long %s" % (gpsFormat(li[1], li[2]),
                                       gpsFormat(li[3], li[4]))


Already looks /prog/-approved.

Name: Anonymous 2012-01-30 12:08

>>5
i like to think this code may have been readable at one point but then you went into ``pythonista show-off mode''

Name: Anonymous 2012-01-30 12:34

>>9
You must not be good at Python if you can't read that. It isn't complicated at all.

Name: Anonymous 2012-01-30 12:57

>>10
Not enough FORCED INDENTATION OF CODE

Name: Anonymous 2012-01-30 13:31

looks okay to me? i'd use less than 8 spaces for indentation, whatever

Name: Anonymous 2012-01-30 13:58

#/* """
Gentlemen, I give you FORCED_INDENTATION.PY v1.0

Save it somewhere and pipe in some code with tabs in it. Watch the magic happen!

Usage: cat input | python FORCED_INDENTATION.PY [Number of tabs to be multiplied] > outfile
""" #*/


import sys

if __name__ == "__main__": #{
    if len(sys.argv) != 2: #{
        exit()
    #}

    MOAR_INDENTS_FOR_PROG = int(sys.argv[1])
    TABULAR_MASTER_RACE      = "\t"

    while 1: #{
        NEEDS_MORE_INDENTS = ""

        try: #{
            NEEDS_MORE_INDENTS = raw_input()
        #}
        except EOFError: #{
            exit()
        #}

        print NEEDS_MORE_INDENTS.replace(TABULAR_MASTER_RACE, TABULAR_MASTER_RACE*MOAR_INDENTS_FOR_PROG)
    #}
#}

Name: Anonymous 2012-01-30 14:08

#/* """
You know this doesn't start a multiline string, right?

Name: Anonymous 2012-01-30 15:30

>>14
doesn't matter if you're trying to plug FIOC

Name: Anonymous 2012-01-30 15:36

>>15
All you need to do is from __future__ import braces.

Don't change these.
Name: Email:
Entire Thread Thread List