123 Posted Topics
Re: it should not matter if you put $yr or ${yr}. Show your entire code that defined the variables.. | |
Re: [code] a="2007-05-10" b="2007-06-10" awk -v a="$a" -v b="$b" 'BEGIN{ n=split(a,tmpa,"-") m=split(b,tmpb,"-") if ( ( tmpa[1] <= tmpb[1] ) && ( tmpa[2] <= tmpb[2] ) ){ print "correct" } else { print "not correct"} } ' [/code] | |
Re: why do you think that regular expression is the way to go? [code] >>> s1 =' 25000 ' >>> s1.replace(" ","") '25000' >>> s2 = ' 5.5910 ' >>> s2.replace(" ","") '5.5910' [/code] regular expressions will be the last in mind for solving string problems in Python, unless really desperate | |
Re: it would be better to show a sample input file, your expected output as well. to search in a file. just an example...considering i don't know what your file structure is like. [code] for line in open("file"): if "john" in line: d['john'] = line [/code] | |
Re: since this is homework, i will show an example. you follow up with the rest. [code] awk '/<tag1>/ { gsub("<tag1>|</tag1>","") printf "%s|",$0 t1 = t1 sprintf("%s|",$0) }END {print t1}' "file" [/code] | |
Re: [code] awk '/^$/{next} { $1=$1"Reportgenerate";print } ' "file" [/code] | |
Re: another way [code] >>> for i in range(len(sentence.split()),0,-1): ... print sentence.split()[i-1], [/code] | |
Re: you can save your IP in a file. check for file existence and if exists, read it and save the IP contained in the file into variable. then check your IP, comparing it with the variable. If not the same, email | |
Re: [code] tr '\n' ',' < file [/code] | |
Re: [QUOTE=alexxxprog;379083] ... numbermaxfile4folder=here I have to assign a RANDOM BETWEEN 300 AND 600 (how ???) ... [/QUOTE] [code] # start=300 # end=600 # echo $(($RANDOM % ( $end - $start + 1 ) + $start)) 401 [/code] [quote] (to fill up a file of an amount of bytes..it should be … | |
Re: [QUOTE=StrikerX;374666]I guess this what you are looking for something like this [code] #!bin/python num = int(input("Enter number : ")) #getting the starting number . while (num < 100): #start the loop . print "it's less than 100, add more numbers ." another_num = int(input("Enter number : ")) num = num … | |
Re: why do you need to swap files? do you just want to swap filenames? swap file contents?? what exactly are you trying to do for your project? | |
Re: [QUOTE=Matt Tacular;375930][code]str1 = 'c:\documents and settings\user\desktop' str2 = 'starcraft.exe' print str1[/code] I would like to know how it would be possible to add str2 to the end of str1 with a "\" inbetween the two strings. so that I end up with "c:\documents and settings\user\desktop\starcraft.exe". Thanks[/QUOTE] one method i always … | |
Re: bash's parameter substitution is a good feature to have, but it has ugly syntax. for what you want to do, you can use awk [code] awk -F":" '{print $3,$1}' /etc/passwd [/code] | |
Re: check the man page of who command. for reading the text file, you can use while loop eg just an example [code] while read user do who |grep $user if [ $? -eq 0 ];then echo "user $user logged in fi done < "file" [/code] | |
Re: [QUOTE=migg_21;365359]awk '{print NR SEP $0}' SEP="/ " exfile1.txt > try2.txt here is a awk scritp which copies the contents form one to anthor it works well, but how do I change it to copy the contents in to several files ? can any one help please[/QUOTE] you can invoke the … | |
Re: [QUOTE=masijade;363030]sed -e 's/\+62018\([0-9]+\)\+\+/+62018\10++/' infile > outfile[/QUOTE] it doesn't work at my side: [code] # sed -e 's/\+62018\([0-9]+\)\+\+/+62018\10++/' file UNB+UNOA:1+5030917029608:14+5000119000006:14+070509:0850+62018000100020++INVOIC [/code] @OP:try this [code] awk 'BEGIN{FS="+";OFS="+"}$6~/^62018/{ $6=$6"0"}{ print $0 }' file [/code] | |
Re: Personally, i would use a loop for this. [code] num = 32 b1 = 10 b2 = 2 x = 1 while 1: if num%(b2**x) < num: x = x + 1 continue else: break print x [/code] | |
Re: [code] echo "123" | awk ' /^[0-9]+$/ { print "a number" }' [/code] | |
Re: just use the for loop to go over each item, then manipulate from there [code] >>> for i in alist: ... print ' '.join(map(str,i)) ... 2934110 B1 D4 7C7C7C7C804040404040F140404000 2934110 5 1 1 01 Actes Sud 2934110 4 1 2 8C00Dubbelganger (motief) 2934110 3 1 1 01 01 03 Les … | |
Re: is this what you are looking for [code] >>> s = "this is a string" >>> alist = list(s) >>> alist ['t', 'h', 'i', 's', ' ', 'i', 's', ' ', 'a', ' ', 's', 't', 'r', 'i', 'n', 'g'] >>> [/code] | |
Re: well, don't even have to use wc. [code] number_of_line=$(awk 'END {print NR}' file) [/code] | |
Re: [code] #!/usr/bin/bash arg=$1 awk -v var=$arg '{ gsub(/yes/,var,$0); print }' file [/code] output: [code] #./test.sh this is a test file crap i am cool [/code] | |
Re: [QUOTE=sneekula;317307]I want to see if a certain word is in a text file, how do I go about that?[/QUOTE] you can read in line by line [code] for line in open("file"): if "word" in line: do_something(line) [/code] you can read in one whole chunk [code] data = open("file").read() if "someword" … | |
Re: OP wants to collect IP address of browser. So guess he may be using CGI. here's an [URL="http://www.shindich.com/sources/cgi/clientip/clientip.py"]example[/URL] | |
Re: [QUOTE=Gumster;332231]Hi all, im gumster new to DaniWeb, been programming vb for numerous years moving to python anyway, Im trying to create a small authentication module for a program im making where it asks for the username and password, i was just wondering how i go about masking the password so … | |
Re: Sincef you are new to python, i suggest you take the tutorial [URL="http://www.python.org/doc/"]here[/URL]. | |
Re: split will break if your input have punctuations. eg word.Test . This will be counted as 1? (although a blank space comes after a full stop.) anyway, here's another way to do it, [code] >>> import re >>> s = "This program will calculate the average word length in a … | |
Re: [code] s = "open sesame" print s[0:s.index('n')] + s[ s.index('n') +1 : ] [/code] | |
Re: [QUOTE=wandie;321786]:sad: Please could some please help me out here . I have an array. I want to count how my 'a' appear and the a must have its quotes 'a' [code][(' ', ' ', [('a', 'Scott'), ('9', 'vth')]), (' ', ' ', [('a', 'Jenny'), ('9', 'vth')])][/code] Like this one has … | |
Re: you should read the docs more. also googling with "Python word count" will show you some links to what you are looking for. | |
| |
Re: sys.exit() implements SystemExit, see [url]http://docs.python.org/lib/module-sys.html[/url] | |
Re: Or you could do this [code] import operator a = (1,2,3,4) b = (4,3,2,1) print sum(map(operator.mul,a,b)) [/code] | |
Re: [QUOTE=Mushy-pea;304763] Could someone tell me the kind of commands I need to research to do stuff with text like this? I can work out the rest. Any help appriciated. [/QUOTE] Tools such as sed/awk/perl are used for text processing. they make use of regular expressions alot. So you need to … | |
Re: if all you need is to add a specific word to the end of each line (which contains one word ), then a batch file will suffice. An example [code] @echo off for /F %%i in (file.txt) do echo %%iweb [/code] This will add the word "web" to the current … | |
Re: another way is to use the "|" special character. [code] >>> re.findall(r'\d+\.\d+|\d+',data_raw) ['20', '35', '40', '84', '100', '245.99'] >>> [/code] | |
Re: [QUOTE=danizzil14;305036]I think thats what they are called, it's the -command thing you put after the exe's name, to give it a specific start up property. Anywho, here's my problem, I run a program called Blender, but it runs really slowly due to an OpenGL glitch, so I have to go … | |
Re: you need to put a decimal before doing the division: [code] >>> 6.0/4 1.5 >>> 6/4.0 1.5 [/code] or you can import future: [code] >>> from __future__ import division >>> 6/4 1.5 >>> [/code] | |
Re: [QUOTE=jorritgoddijn;304580]hi, i need to insert a character in a certain text file. i cannot change the original files so i have to work with that, luckily the files are written in a way that at the end of every second line a semicolon ; has to be inserted. How can … | |
Re: why only vi? from the way i see, you just need to do something to a file and save it. So you can also use sed/awk to do the job. If you still want to try vi, here's one way, not the best, but still does something. [code] sun# echo … | |
Re: assuming data is as first posted: [code] >>> import re >>> re.findall(r"\[(.*)\]",data_raw) ['20 ', ' 35 ', '40 ', '84 ', '100 ', ' 245', ' 260', ' 300 ', ' 440 ', ' 521 ', ' 650 '] [/code] or if they contain spaces like the other posts... [code] … | |
Re: can you try : [code] dates = [i for i in files for j in months if j in i ] [/code] | |
Re: [QUOTE=Matt Tacular;300890] [code] .... if northAmericaCheckDone == 1: return ai_countryToAddMen break [/code] [/QUOTE] you have a return and a break after that. the "break" can be omitted. | |
Re: if you don't want to change list1, you can do [code] list1dup = list1[:] list3 = add_item(list1dup) ... [/code] | |
Re: what is your error, and what is your expected output/results? | |
Re: [QUOTE=sneekula;299775]I took a mixed type list and set out to find the min and max values. The results are very surprising to me: [php]mixed_list = [11, 'Dick', 12, 'Mary', 7, 'Zoe', 9, 700, 777, 'Paul', 13456789] mn = min(mixed_list) mx = max(mixed_list) print mn, type(mn) # 7 <type 'int'> print … | |
Re: if you just want to find "Paul" in your example, one way to do it is to convert that list to string [code] astring = ','.join( str(i) for i in nested_list) if "Paul in astring: print "Found" [/code] |
The End.