- Strength to Increase Rep
- +8
- Strength to Decrease Rep
- -2
- Upvotes Received
- 10
- Posts with Upvotes
- 10
- Upvoting Members
- 7
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
Re: [QUOTE=a1eio;332281]yea, i forgot to mention, i'm trying to do this on a windows machine. the os.popen idea did occur to me, but then i got stuck again.. :p i don't know the dos command for opening the cd drive. thanks a1eio[/QUOTE] if you have pygame, you can use its inbuilt … | |
Re: [QUOTE=Ene Uran;249919]If anyone figures out a different way to sort by word length....[/QUOTE] [code] >>> list1 = ['Herring','used','to','be','abundant','in','the','Atlantic','Ocean','then','herring','got','overfished'] >>> lengthlist = map(len,list1) >>> lengthlist [7, 4, 2, 2, 8, 2, 3, 8, 5, 4, 7, 3, 10] >>> all = zip(lengthlist,list1) >>> all [(7, 'Herring'), (4, 'used'), (2, 'to'), (2, … | |
Re: [QUOTE=Lardmeister;334753]When I run: [code]dec = 255 print hex(dec) [/code]I get 0xff, but I like to get just 'ff'[/QUOTE] '0x' always appears in front, so if you want to use hex() and get rid of 0x, use hex(255)[2:] | |
Re: [QUOTE=chris99;253120] [code] def prompt_rea(): global gold .... .... [/code] Can you see the problem?[/QUOTE] if you want to use gold as global, u might like to put "global gold" inside prompt_rea() | |
Re: [QUOTE=sneekula;317313]I need to read in a text file, replace selected words and write the changed text back out to a file. Is there an easy way with Python?[/QUOTE] there are several ways. 1) reading with for loop [code] o = open("output","a") #open for append for line in open("file"): line = … | |
Re: [QUOTE=sneekula;318529]Is there a reliable way to 'pluralize' english words with Python?[/QUOTE] there are some cookbook recipe in ASPN you can refer to. [URL="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82102"]here[/URL]. they may not be wat you want, but at least will give you a head start | |
Re: you do it systematically using the same way to read single level dict [code]d={'AAA': {'KEY1':'text1', 'KEY2':'text2', 'KEY3': 'text3', 'KEY4': 'text4'}, 'BBB': {'BBB1':{'KEY1':'text1', 'KEY2':'text2', 'KEY3': 'text3', 'KEY4': 'text4'}, 'BBB2':{'KEY1':'text1', 'KEY2':'text2', 'KEY3': 'text3', 'KEY4': 'text4'}, 'BBB3':{'KEY1':'text1', 'KEY2':'text2', 'KEY3': 'text3', 'KEY4': 'text4'}}} for i,j in d.iteritems(): for m,n in j.iteritems(): print m,n [/code] … | |
Re: things can be that easy. [code] $string = "<TEXT> Some text Another text </TEXT>"; @s=split /<\/TEXT>/, $string; $s[0] =~ s/.*<TEXT>// ; print $s[0]; [/code] | |
Re: >>> a = 'nf+nfpermult+nf' >>> a=a.split("+") >>> for n,i in enumerate( a ): ... if i == "nf": a[n]="1.0" ... >>> print '+'.join(a) 1.0+nfpermult+1.0 | |
Re: you are using the "wrong" approach to reading a file. use a for loop [CODE] f=open("file") for line in f: print "do something with ",line f.close()[/CODE] | |
Re: use a html parser for this job, such as BeautifulSoup. If you don't want to, then another way is to read the whole html, split on "</div>", go through each element in the list, check for "<div class="info-content">", if found, replace it will null. You will get your string | |
Re: no need to use regex 1) split on "</a>" 2) go through list, check of List?ratings. 3) get index of ">, 4) print [code] >>> string = '''<a href="/ratings_explained">weighted average</a> vote of <a href="/List?ratings=7">7.2</a> / 10</p><p>''' >>> for i in string.split("</a>"): ... if "List?ratings" in i: ... print i[ i.rindex('">')+2 … | |
Re: it depends on what errors you are looking for. If there are 1000s of errors, are you going to send all 1000 ++ errors to your email?? you have to describe clearly your specs. | |
Re: you can use splitext from os module [code] import os,shutil def renamer(target) : os.chdir(target) for filename in os.listdir('.') : print filename newfilename = os.path.splitext(filename)[0] print newfilename os.rename(filename, newfilename) print "Renamed " + filename + " to " + new_filename shutil.copy("copyme","newcopyme" [/code] | |
Re: use awk [code] awk '/default = ALL/{ print "default = DES-168" print "default = RC2-128" print "default = RC4-128" print "#"$0 next}1' file [/code] | |
Re: [code] # perl -ne 'print if !(/\[SectionOne\]/ .. /\[SectionTWO\]/); ' file Entry1=19 Entry2=hello there [/code] use module like Config::IniFiles is still the best. | |
Re: you can learn the basics of Perl first. One of the many good sources is straight from the doc. type perldoc perl for more info. otherwise, you can always view online Perl doc with your browser. After you are proficient with it, you can play with web frameworks, such as … | |
Re: i think you shouldn't need to worry too much on whether its the correct directory because you would have set it properly when configuring your FTP server. | |
Re: if you have Perl, you can use the MP3::Tag module. eg [code] use MP3::Tag; # set filename of MP3 track my $filename = "test.mp3"; # create new MP3-Tag object my $mp3 = MP3::Tag->new($filename); # get tag information my ($title, $track, $artist, $album, $comment, $year, $genre) = $mp3->autoinfo(); print "$title, $track, … | |
Re: regular expressions are usually not needed for string manipulations. [code] # echo "abcdd" | awk 'BEGIN{FS=""}$2==$3{print "ok"}' # echo "abbdd" | awk 'BEGIN{FS=""}$2==$3{print "ok"}' ok [/code] | |
Re: [code] awk '{printf "%s %s",$0, ($3 > 40)? "yes" :"no"}' file [/code] | |
Re: [QUOTE=pinder;343621]Hi, I'm trying to copy a file in python, I have imported the shutil module My problem is that I want to copy file in a directory beginning with a certain name. Example I have 5 file in the fodler but i want to copy all the one tat begin … | |
Re: [code] awk 'BEGIN{FS="[]].[[]|[[]|[]]"} { gsub(/id|\"/,"",$13) split($3,a,"/") gsub("tag","",$16) print $13,a[1],$7,$16 }' file [/code] | |
Re: without glob module, just search for it [code] import os os.chdir("/somewhere") for files in os.listdir("."): if not "_ab" in files: print files [/code] | |
Re: [QUOTE=bimaljr;689099]Hi, I just need to know a simple command to bulk renaming. I have hundreds of .DEB files. I want to remove [B]4%3a[/B] from all file names. [B]example :[/B] [I]old name :[/I] ark-kde4_4%3a4.0.3-0ubuntu4_i386.deb [I]new name :[/I] ark-kde4_4.0.3-0ubuntu4_i386.deb I know there is a "rename" command but I don't know it's use. … | |
Re: [QUOTE=Gromit;686845]I poked at your original script and made some syntax changes to your "if" statement. I think it does what you want now. I think you have to use brackets when doing a comparison like this: [code] $ cat daniweb.sh #!/usr/bin/bash memUsage=$(ps -C bash -o pid=,size|awk '{SUM += $2} END … | |
Re: better still, no need grep [code] top | awk '/root/{ sum += $10 }END {print sum}' [/code] | |
Re: Look at the bash guide [URL="http://tldp.org/LDP/abs/html/testbranch.html"]here[/URL]. It has examples on checking for upper case. | |
Re: sed will be slower than tail for huge files. Just a tip |