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
king_kilr
May 25, 2007

No Safe Word posted:

change that to print ''.join(sorted(line)) and you will get the strings you're looking for

you probably want line.strip("\r\n"), that way you don't get random linebreaks (unless you want them of course)

Adbot
ADBOT LOVES YOU

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Learning the basics here and ran into a problem:

code:
database = {
    'john':'denver',
    'paul':'arizona',
    'rachel':'north carolina'
    }

for i in database: print i, 'is in', database[i]
that gives me:
rachel is in north carolina
paul is in arizona
john is in denver

Could someone explain why it prints outs rachel first and not john?

spankweasel
Jan 4, 2006

Hughmoris posted:

Learning the basics here and ran into a problem:

code:
database = {
    'john':'denver',
    'paul':'arizona',
    'rachel':'north carolina'
    }

for i in database: print i, 'is in', database[i]
that gives me:
rachel is in north carolina
paul is in arizona
john is in denver

Could someone explain why it prints outs rachel first and not john?

From http://docs.python.org/library/stdtypes.html#mapping-types-dict

quote:

CPython implementation detail: Keys and values are listed in an arbitrary order which is non-random, varies across Python implementations, and depends on the dictionary’s history of insertions and deletions.

Python 2.7 does have ordered dictionaries here:

OrderedDict

Lonely Wolf
Jan 20, 2003

Will hawk false idols for heaps and heaps of dough.
Dictionaries are unordered. If you want to preserve order you can do a list of tuples but you'll have to search every element in the list and compare to the first element of the tuple which is significantly more work.

Hughmoris
Apr 21, 2007
Let's go to the abyss!

spankweasel posted:

From http://docs.python.org/library/stdtypes.html#mapping-types-dict


Python 2.7 does have ordered dictionaries here:

OrderedDict

Makes sense, thank you.

ATLbeer
Sep 26, 2004
Über nerd

Hughmoris posted:

Learning the basics here and ran into a problem:

code:
database = {
    'john':'denver',
    'paul':'arizona',
    'rachel':'north carolina'
    }

for i in database: print i, 'is in', database[i]
that gives me:
rachel is in north carolina
paul is in arizona
john is in denver

Could someone explain why it prints outs rachel first and not john?

So, you got the dictionary is unordered bit but, indulge me for a bit here. Sometimes you can actually tell what programming language a new programmer is coming from by syntax styling but, I can't seem to figure it out here. Learning Python is almost as much about learning the "style" and being "Pythonic" as it is learning the basics.

code:
for i in database: print i, 'is in', database[i]
The best learning tool you have is the Python command line, let's take a look at your dictionary.

If you don't know about it already the "dir" command and the "__doc__" method is your new friend

code:
>>> dir(database)
['__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__', 
'__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', 
'__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', 
'__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', 
'__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__',
'__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'has_key', 
'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'pop', 'popitem', 
'setdefault', 'update', 'values']
Dictionaries have a slew of built in functions here and when you want to iterate over a loop these come in handy.

code:
>>> database.iteritems.__doc__
'D.iteritems() -> an iterator over the (key, value) items of D'
code:
>>> for name, city in database.iteritems():
...     print "%s is in %s" % (name, city)
... 
rachel is in north carolina
paul is in arizona
john is in denver
>>> 
So walking through this here, I am iterating over the function database.iteritems(). This function each look gives me a tuple of items in the dictionary
code:
>>> database.iteritems().next()
('rachel', 'north carolina')
Python can automatically expand tuples if you give it a chance
code:
>>> name, city = database.iteritems().next()
>>> name
'rachel'
>>> city
'north carolina'
So on each iteration of the look we are assigning name and city the values from the dictionary

Then printing out on each loop. It's safer and cleaner.
code:
print "%s is in %s" % (name, city)
I'm telling Python that I want to print "is in" but, before and after I have "%s", this means I have a string that needs to be filled in there.

Modern Pragmatist
Aug 20, 2008
I need to provide someone with a standalone piece of software that requires a database. What is the best option for this? I would like to keep the third-party software they may have to install to a minimum. Also, the size of the database will be ~100,000 entries.

Would it be easier to just have a mysql database hosted on my webserver and have the client software query this database?

king_kilr
May 25, 2007
Just use SQLite, included with every python since 2.5.

Modern Pragmatist
Aug 20, 2008

king_kilr posted:

Just use SQLite, included with every python since 2.5.

Ok, that's what I figured, I just wasn't sure if at a certain size, a particular database may be better than another.

Hughmoris
Apr 21, 2007
Let's go to the abyss!

ATLbeer posted:

So, you got the dictionary is unordered bit but, indulge me for a bit here. Sometimes you can actually tell what programming language a new programmer is coming from by syntax styling but, I can't seem to figure it out here. Learning Python is almost as much about learning the "style" and being "Pythonic" as it is learning the basics.

Thanks for the write-up. You can't figure out my terrible styling because I don't have any, this is my first language. I've been extremely bored lately so I'm trying to teach myself Python, again.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Modern Pragmatist posted:

Ok, that's what I figured, I just wasn't sure if at a certain size, a particular database may be better than another.

Somewhere around the ten-million-row mark, postgres probably becomes a better option than sqlite; the exact point depends on your schema and usage requirements, but sqlite is low-overhead enough that it competes rather well with the "real" database servers. For single-user setups you can often still get away with distributing raw database files and just running postgres in single-user mode rather than requiring users to configure the daemon and connect over a socket.

If you start wanting more database features than sqlite provides you should also migrate to postgres; sqlite is an extremely bare-bones database and even very small applications may find it lacks some highly desirable feature.

Shaocaholica
Oct 29, 2002

Fig. 5E
Given a volume label or drive letter in windows, is there any way to pull the model name of the physical drive?

Ex. 'FreeAgent Go'

I have a tool that copies files from the network to a portable hard drive and re-paths and re-names them and it also builds a log file of all the files. In that log file I want to put the actual model of the portable drive for tracking purposes. I've looked through the docs for pywin and none of the modules seem to have access to that data. I could grab the output of some command and parse it for the drive model but I don't know which native windows commands would even do that.

ATLbeer
Sep 26, 2004
Über nerd

Shaocaholica posted:

Given a volume label or drive letter in windows, is there any way to pull the model name of the physical drive?

Ex. 'FreeAgent Go'

I have a tool that copies files from the network to a portable hard drive and re-paths and re-names them and it also builds a log file of all the files. In that log file I want to put the actual model of the portable drive for tracking purposes. I've looked through the docs for pywin and none of the modules seem to have access to that data. I could grab the output of some command and parse it for the drive model but I don't know which native windows commands would even do that.

fsutil?

Shaocaholica
Oct 29, 2002

Fig. 5E

ATLbeer posted:

fsutil?

Hmm, couldn't find anything using that to get that info.

Shaocaholica
Oct 29, 2002

Fig. 5E
I guess another way about it would be to access the disk management module in windows. Not sure if there are any python modules to do that or just resorting to capturing command line stuff.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Shaocaholica posted:

I guess another way about it would be to access the disk management module in windows. Not sure if there are any python modules to do that or just resorting to capturing command line stuff.

I think you'd probably get more help with this in one of the Windows threads by just asking about general ways to get the info you need and then figuring out how to implement those ways in Python.

Shaocaholica
Oct 29, 2002

Fig. 5E

Thermopyle posted:

I think you'd probably get more help with this in one of the Windows threads by just asking about general ways to get the info you need and then figuring out how to implement those ways in Python.

good call

Threep
Apr 1, 2006

It's kind of a long story.

Shaocaholica posted:

Given a volume label or drive letter in windows, is there any way to pull the model name of the physical drive?

Ex. 'FreeAgent Go'

I have a tool that copies files from the network to a portable hard drive and re-paths and re-names them and it also builds a log file of all the files. In that log file I want to put the actual model of the portable drive for tracking purposes. I've looked through the docs for pywin and none of the modules seem to have access to that data. I could grab the output of some command and parse it for the drive model but I don't know which native windows commands would even do that.
I haven't done any Win32 API from Python but this looks like a good starting point:
wmi module
Win32_DiskDrive

edit:
code:
import wmi
c = wmi.WMI()
for logical in c.Win32_LogicalDisk(DeviceID='H:'):
    for part in logical.associators(wmi_result_class='Win32_DiskPartition'):
        for phys in part.associators(wmi_result_class='Win32_DiskDrive'):
            print phys.Model
Now someone post the non-horrible way to do it.

Threep fucked around with this message at 22:45 on Jul 15, 2010

Hughlander
May 11, 2005

I've gone back and forth on this a few times, and am not sure what the best way to handle it is... I've got a Django project with a bunch of dependencies on other code bases. Originally I created a virtualenv, pip installed the dependencies by name, then put the virtualenv environment into git. This was a horrible idea given a mix of x86, x64, Linux, and win32. Also this had the problem that several of these projects didn't have a stable release anytime recently and many recommended syncing to trunk and running from there.

So on my second pass, I made an external-src directory, svn/git/bzred the required projects into there, created an update file to sync them all to head/trunk, and then made a .pth file for all the directories. Now the virtualenv would have a single thing installed by pip, virtualenvwrapper, and I'd use add2virtualenv the external-src dir.

This works 'ok' until I saw the dependency file for one of these requirements and really wished that I could use pip again but from the head/trunk of the repositories and more importantly have a 'pip update' mode to grab new versions from wherever the code was originally installed.

What's the normal way to deal with something like this? I've lucked out atm that all the modules i need to install are 100% python, because just pointing a .pth file won't work if it needs to be compiled as well.

king_kilr
May 25, 2007
You don't put your venvs in your repo. My venvs live in ~/.virtualenvs/, you check in a requirements.txt which is a list of things to be installed, and then anyone else can install them with pip install -r requirements.txt.

ATLbeer
Sep 26, 2004
Über nerd

king_kilr posted:

You don't put your venvs in your repo. My venvs live in ~/.virtualenvs/, you check in a requirements.txt which is a list of things to be installed, and then anyone else can install them with pip install -r requirements.txt.

Yep

code:
pip freeze > requirements.txt

pip install -r requirements.txt

BeefofAges
Jun 5, 2004

Cry 'Havoc!', and let slip the cows of war.

Threep posted:

I haven't done any Win32 API from Python but this looks like a good starting point:
wmi module
Win32_DiskDrive

edit:
code:
import wmi
c = wmi.WMI()
for logical in c.Win32_LogicalDisk(DeviceID='H:'):
    for part in logical.associators(wmi_result_class='Win32_DiskPartition'):
        for phys in part.associators(wmi_result_class='Win32_DiskDrive'):
            print phys.Model
Now someone post the non-horrible way to do it.

The even-more-horrible way I did it (out of laziness) was by using diskpart through subprocess. I'm actually about to release that code as part of an open source project, so if you're willing to use horrible (but working) code you can use my stuff after I release it in a few days.

Hughlander
May 11, 2005

king_kilr posted:

You don't put your venvs in your repo. My venvs live in ~/.virtualenvs/, you check in a requirements.txt which is a list of things to be installed, and then anyone else can install them with pip install -r requirements.txt.

What if you want to always use the trunk of the software while you're still developing it? Some of the projects are moving targets right now and if you report a bug the response is 'use head/trunk' is there an easy way to upgrade pip to the latest from trunk or do you just rm -rf and reinstall while have requirements not with ==?

bitprophet
Jul 22, 2004
Taco Defender

Hughlander posted:

What if you want to always use the trunk of the software while you're still developing it? Some of the projects are moving targets right now and if you report a bug the response is 'use head/trunk' is there an easy way to upgrade pip to the latest from trunk or do you just rm -rf and reinstall while have requirements not with ==?

You read the pip docs? ;)

Kosani
Jun 30, 2004
Ni ni.
Someone was kind enough to supply me with some sample code from a repository that accomplished something very similar to the objective of my project. (To take scrambled words as an input and descramble them based off of a 'master word list')


code:
word_list = ["pants", "fart", "hello", "dog", "god"]

letter_sorted_words = dict()

# build mapping
for word in word_list:
    sorted_letters = "".join(sorted(word))
    potentials = letter_sorted_words.get(sorted_letters, set())
    potentials.add(word)
    letter_sorted_words[sorted_letters] = potentials

def dejumble(jumbles):
    return dict([(j, letter_sorted_words.get("".join(sorted(j)))) for j in jumbles])



jumbled_words = ["afrt", "anpst", "ehllo", "ogd"]

for jumbled, potentials in dejumble(jumbled_words).iteritems():
    print "%s could be %s" % (jumbled, ", ".join(potentials)
Now this is my first python project. I've been staring at this piece of code for a good....three hours now and I still can't make any sense of it. I was hoping that someone could just briefly explain what each line means/does? I feel like since I have so much invested in trying to figure this piece of code out that such an explanation would do a great deal in helping me learn this language.

Haystack
Jan 23, 2005





Having just recently learned Python, I can sympathize. That said, I'm not sure what your experience level is. If you brand spanking new, reading the documentation, the official tutorial and maybe Think Python will be more helpful than trying to parse this code cold.

Assuming you know the basics (how lists, for-loops, and dictionaries work, etc.). Let's look at the main for loop:
code:
# build mapping

for word in word_list:
    sorted_letters = "".join(sorted(word))
    potentials = letter_sorted_words.get(sorted_letters, set())
    potentials.add(word)
    letter_sorted_words[sorted_letters] = potentials

The purpose of this loop is to use a list of strings to create a dictionary which maps the alphabetized version of the strings (ie, "hats" becomes "ahst") to the set of strings that can create that alphabetization (so "ahst" would map to both "hats" and "shat"). End result will be something like {ahst:set("hats","shat")}.

The line:
code:
    sorted_letters = "".join(sorted(word))
Is what actually alphabetizes each word. What happens is that sort(word) returns a sorted list of the characters in the word. The list is then stuffed into an empty string (that's the "".join() bit).

code:
    potentials = letter_sorted_words.get(sorted_letters, set())
This line makes use of the .get() method that all python dictionaries have built-in. You can read letter_sorted_words.get(key, default) as "look in the dictionary letter_sorted_words for this key; if it exists, return its value; otherwise return this default value (or None, if no default is specified)." So in this case you're looking in letter_sorted_words to see if the alphabetized word is already a key, and otherwise returning an empty set (I'll get to sets in a minute).

.get() is very convenient, and you'll set it used everywhere.

code:
    potentials.add(word)
This adds the word to the set you got in the last line. A set is very much like a list, except 1) sets do not preserve order and 2) sets can only have one copy of any given value. So set(1,1,2,2) is the same thing as set(2,1).


code:
    letter_sorted_words[sorted_letters] = potentials
This creates the actual mapping of alphabetized word to source words. It makes sorted_letters a key in the dictionary with the set potentials as it's value.

Hopefully that's enough of a start for you to figure out the rest of your code.

onecircles
May 6, 2009
I see that this thread is mostly occupied with answering and asking questions relating to the actual business of coding in python, so I hope you won't mind if I ask a more general, non-technical question regarding python as it compares to other programming languages.

I have recently become interested in learning to program. I have a little experience with c and c++. I used to be impressed by the idea of learning a low level language, due to the efficiency and speed, but I've come around on that and now I just want a language that will get out of my way and let me make stuff.

I mainly want to learn to program to make videogames, so I had considered learning the language that is packaged with game maker 'GML' but I want to learn a language that is at least somewhat useful outside videogames so that idea is out.

After some research I had decided upon python 2.6 with pygame, but earlier today I had a conversation with a software engineer friend of mine, and he strongly suggested I go with java instead. He actually suggested about everything except python. He seemed to have a negative view of it.

His rationals were that python is not marketable. Python is not good for object oriented programming and that python is not actually as useful as I thought it was.

If I was going to learn python he suggested I go with J-thon.

So I'm a beginning programmer, and I mainly want to make more complex and fully featured versions of older game genre's like side scrolling platformers and such. I'm not really interested in working with advanced 3d graphics. I also want a language that will let me do other little weird projects that I think of.

Is python a good language for a beginning programmer that wants to make games?

redleader
Aug 18, 2005

Engage according to operational parameters
So I'm working on a lovely newbie Python project using libtcod, which is a library for roguelike development. I'm using it specifically for its file parser, so that I can hopefully go in and edit libtcod-style config files. I have, inevitably, run into some trouble with both understanding how the parser works, and actually using it.

The libtcod parser is somewhat documented. To use it, you first set up a Listener class for the parser. This class contains a whole bunch of methods (I think that's what they're called) that the parser uses somehow:
code:
class ThingListener:
    def new_struct...     # set up methods for the parser to handle events
    def new_flag...
    def new_property...
Once you've got your listener class, you then initialise the parser, set up all the structures in the config file, and run the parser:
code:
pars = libtcod.parser_new()
initialise_parser(pars)        # do stuff to make the parser understand the data file
libtcod.parser_run(pars, 'config.dat', ThingListener())
I've obviously omitted a whole bunch of irrelevant code for setting up the class. The gist of it is that the parser runs on the config file, and somehow is calling the methods in the listener class: running new_struct(...) whenever it finds a new struct, new_flag(...) for a new flag, etc. I believe this is similar to SAX for XML parsing.

I have a couple of questions:
- What is that last line of code doing?
code:
libtcod.parser_run(parser, 'config.dat', ThingListener())
This is obviously the thing that makes the parser actually run, but how does it work? I guess that might be a bit hard to understand without reference to the underlying library. What is going on with that ThingListener() argument? It looks like it's 'calling' (I guess) the class ThingListener in some way. I've seen reference to the parser working with callbacks - is this using a callback to a class or something?

- I want to use the ThingListener class to use data from the parser to make a bunch of Thing objects (instances, I guess), and put them in a list of some sort. However, I don't see any way of doing this. I guess you'll have to initialise your Thing instances inside the listener, but I can't see any way of cleanly doing this. My assumption is that when the parser finishes, anything done inside the ThingListener will go out of scope. I can only find C++ examples of the parser in action, and that's way over my head.

To clarify, I've got the parser working in a very basic way - it just prints out the data in the config file with some slight formatting. I just can't do anything useful with it.

Sorry about this long, rambling, confused idiot newbie post :)

unixbeard
Dec 29, 2004

onecircles posted:

Is python a good language for a beginning programmer that wants to make games?

if you're on windows i'd say go with c#. if you're still pretty new to programming you have a lot to get to grips with, nothing insurmountable but if you jump right in you might find it too confusing. Start simple and make something like pong, then go from there.

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

onecircles posted:

His rationals were that python is not marketable. Python is not good for object oriented programming and that python is not actually as useful as I thought it was.

So I'm a beginning programmer, and I mainly want to make more complex and fully featured versions of older game genre's like side scrolling platformers and such. I'm not really interested in working with advanced 3d graphics. I also want a language that will let me do other little weird projects that I think of.

Is python a good language for a beginning programmer that wants to make games?

It sounds to me that for what you want to do, Python is perfect. Your friend is correct in that nobody out there is going to give you a job writing pygame games, but that doesn't really sound like a problem at this point. Yes, if you want to get a "real" job writing "real" games, you're going to have to learn one of those horrible "real" languages like Java or C or whatever the kids are writing things in these days. But you're probably going to have way more fun writing side scrollers with pygame.

His other objections are just silly, though. Python is certainly plenty marketable in the general sense, and way more useful than he seems to think it is. His comment about OOP makes sense if you keep in mind that if Java were a person, it would probably have aspergers.

Kosani
Jun 30, 2004
Ni ni.
Thank you, haystack. That explanation really did help.

Other questions:

I have a text file. In this textfile is just line after line of words in this fashion:
code:
word1
word2
word3
word4
How do I reference things in a text document by line? I have a variable set up for the text document but if I, for example, try to "print word_list[0]" it will print the first letter of line 1 rather than the first line of the list. What I want to do, however, is reference the items out of the text on a per-line basis. I want to retrieve the entirety
of "word1" in my example list.

How would I do that?

Thanks again.

Sailor_Spoon posted:

His comment about OOP makes sense if you keep in mind that if Java were a person, it would probably have aspergers.
Hahahahaha. Nice.

Kosani fucked around with this message at 18:32 on Jul 18, 2010

Ferg
May 6, 2007

Lipstick Apathy

Sailor_Spoon posted:

His comment about OOP makes sense if you keep in mind that if Java were a person, it would probably have aspergers.

This is the best possible description of Java, ever.

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

Kosani posted:

Thank you, haystack. That explanation really did help.

Other questions:

I have a text file. In this textfile is just line after line of words in this fashion:
code:
word1
word2
word3
word4
How do I reference things in a text document by line? I have a variable set up for the text document but if I, for example, try to "print word_list[0]" it will print the first letter of line 1 rather than the second line of the list. What I want to do, however, is reference the items out of the text on a per-line basis. Like I want to retrieve the entirety
of "word1" in my example list.

How would I do that?

file.readlines()

alternatively s.splitlines()

Note that the first one keeps in the "\n"s whereas the second one doesn't.

Jonnty fucked around with this message at 18:31 on Jul 18, 2010

Kosani
Jun 30, 2004
Ni ni.

Jonnty posted:

file.readlines()

alternatively s.splitlines()

Note that the first one keeps in the "\n"s whereas the second one doesn't.

hmm. I think im missing something here.

lets say I have something real simple:

code:
text_file = open("wordlist.txt", "r")
word_list = ''.join(text_file)
are you saying

if I do "print word_list.readline(1)"

it should print the first line from my txt file word list?

Total newbie question I know sorry.

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

Kosani posted:

hmm. I think im missing something here.

lets say I have something real simple:

code:
text_file = open("wordlist.txt", "r")
word_list = ''.join(text_file)
are you saying

if I do "print word_list.readline(1)"

it should print the first line from my txt file word list?

Total newbie question I know sorry.

Well, firstly, you're not using open in the "right" way. "open" returns something called a file object, which can be used for reading from an navigating around the file (google it to learn more). Your snippet seems to work by python magic, but you should probably be explicit about it.

So, to open and read the file into a string, you should do this:

code:
text_file = open("wordlist.txt", "r")
text = text_file.read()
so that text is now a string containing the text in wordlist.txt. From here you could do:

code:
word_list = text.splitlines()
which would split text into a list where each element is a successive line of the file, or you could just cut to the chase and do:

code:
word_list = text_file.readlines()
using the file object directly. However, this leaves a '\n' at the end of all appropriate lines, so to get rid of those you'll want to do a fun list comprehension:

code:
word_list = [line.strip() for line in word_list]
which strips out all whitespace from around each line, which includes the non-printing '\n' character.

Lonely Wolf
Jan 20, 2003

Will hawk false idols for heaps and heaps of dough.
That's a valid use of a file object, just not what he intended. If you use a file object as an iterator it defaults to readlines so your code could be expressed more simply as:

code:
word_list = open("wordlist.txt", "r")
words = [line.strip() for line in word_list]

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

onecircles posted:

Is python a good language for a beginning programmer that wants to make games?

You can make the games you describe just fine. Additionally, I don't think you'll ever regret having learned Python as it makes a great tool to solve problems. So if in the future you want to move on to C++ or whatever, Python is always going to be there for you with loving arms.

onecircles
May 6, 2009
Thanks guys. I was hoping you would tell me what I wanted to hear, and you have succeeded. As a new programmer I think python is a good choice, It will make the process of learning to program easier. It has the ability to use c/c++ extensions so I can expand in that direction in the future. Plus there's this article on how developing software in python is 5-10x faster than java, never mind more low level languages.

http://pythonconquerstheuniverse.wordpress.com/category/java-and-python/

I think my software engineer friend might just be racist against pythons. :downsrim:

Kosani
Jun 30, 2004
Ni ni.
Perfect! Thank you guys. With this I can try to take it a step further in developing this project. I'll post it when I reach another mile stone.

Adbot
ADBOT LOVES YOU

Kosani
Jun 30, 2004
Ni ni.
ok so another segment of my code is meant to extract a list of 10 words from a really big and hairy .txt file

lets say it goes something like this:

code:
jin = open("d1.txt", "r")

jumble = [line.strip() for line in jin]

print jumble[135:145]
and my output looks like this:

code:
['# List of scrambled words:    \tbbbua1', '# \tiadlgit', '# \ttooatt', '# \tneferd', '# \tslseim', '# \tabb1ub', 
'# \tnmaoic','# \tsalnpoe', '# \tdwaern', '# \tiongid']
but I want it to look like this:

code:
['bbua1', 'iadlgit', 'tooatt', 'neferd', 'sleim', 'tabblub', 'nmaoic', 'salnpoe', 'dwaern', 'iongid']
What would I need to write for it to disregard the '# \t' before every word?
Thanks again!

Kosani fucked around with this message at 20:08 on Jul 19, 2010

  • Locked thread