123 Posted Topics

Member Avatar for chunchuwar
Member Avatar for chunchuwar
0
105
Member Avatar for dave_nithis

[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]

Member Avatar for ghostdog74
0
1K
Member Avatar for jobs

why do you think that regular expression is the way to go? [code] >>> s1 ='&nbsp;25000&nbsp;' >>> s1.replace("&nbsp;","") '25000' >>> s2 = '&nbsp;5.5910&nbsp;' >>> s2.replace("&nbsp;","") '5.5910' [/code] regular expressions will be the last in mind for solving string problems in Python, unless really desperate

Member Avatar for ghostdog74
0
108
Member Avatar for axn

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]

Member Avatar for ghostdog74
0
119
Member Avatar for Sudarshan_Kanna

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]

Member Avatar for ghostdog74
0
151
Member Avatar for samirs79
Member Avatar for Lardmeister

another way [code] >>> for i in range(len(sentence.split()),0,-1): ... print sentence.split()[i-1], [/code]

Member Avatar for vegaseat
0
1K
Member Avatar for 6figganigga

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

Member Avatar for 6figganigga
0
88
Member Avatar for slbit
Member Avatar for alexxxprog

[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 …

Member Avatar for alexxxprog
0
211
Member Avatar for Zorbie

[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 …

Member Avatar for jrcagle
0
273
Member Avatar for atul_saxenas

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?

Member Avatar for ghostdog74
0
86
Member Avatar for Matt Tacular

[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 …

Member Avatar for ghostdog74
0
184
Member Avatar for bergy_nj

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]

Member Avatar for ghostdog74
0
123
Member Avatar for bufospro

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]

Member Avatar for ghostdog74
0
139
Member Avatar for migg_21

[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 …

Member Avatar for ghostdog74
0
178
Member Avatar for gogo3624

[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]

Member Avatar for masijade
0
74
Member Avatar for jwjazz

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]

Member Avatar for jrcagle
0
138
Member Avatar for obscured47
Member Avatar for obscured47
0
98
Member Avatar for wandie

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 …

Member Avatar for wandie
0
104
Member Avatar for aot

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]

Member Avatar for aot
0
132
Member Avatar for jamshid
Member Avatar for jamshid
0
93
Member Avatar for ShaneUniStudent

[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]

Member Avatar for ghostdog74
0
206
Member Avatar for sneekula

[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" …

Member Avatar for sharma_vivek82
0
196
Member Avatar for maxcell
Member Avatar for winz
Member Avatar for nitinloml

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]

Member Avatar for ghostdog74
0
90
Member Avatar for Gumster

[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 …

Member Avatar for ghostdog74
0
3K
Member Avatar for aloishis89

Sincef you are new to python, i suggest you take the tutorial [URL="http://www.python.org/doc/"]here[/URL].

Member Avatar for aloishis89
0
162
Member Avatar for pyguy25

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 …

Member Avatar for ghostdog74
0
12K
Member Avatar for the_python

[code] s = "open sesame" print s[0:s.index('n')] + s[ s.index('n') +1 : ] [/code]

Member Avatar for jrcagle
0
5K
Member Avatar for wandie

[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 …

Member Avatar for wandie
0
847
Member Avatar for sneekula

you should read the docs more. also googling with "Python word count" will show you some links to what you are looking for.

Member Avatar for vegaseat
0
118
Member Avatar for caranjo
Member Avatar for danizzil14

sys.exit() implements SystemExit, see [url]http://docs.python.org/lib/module-sys.html[/url]

Member Avatar for ghostdog74
0
166
Member Avatar for Shark7

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]

Member Avatar for Shark7
0
355
Member Avatar for Mushy-pea

[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 …

Member Avatar for kuom
0
108
Member Avatar for coolvision

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 …

Member Avatar for MidiMagic
0
168
Member Avatar for bumsfeld

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]

Member Avatar for bumsfeld
0
1K
Member Avatar for danizzil14

[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 …

Member Avatar for danizzil14
0
195
Member Avatar for Matt Tacular

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]

Member Avatar for Matt Tacular
0
108
Member Avatar for jorritgoddijn

[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 …

Member Avatar for jim mcnamara
0
96
Member Avatar for amitc

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 …

Member Avatar for ghostdog74
0
122
Member Avatar for wandie

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] …

Member Avatar for ghostdog74
0
161
Member Avatar for jrcagle

can you try : [code] dates = [i for i in files for j in months if j in i ] [/code]

Member Avatar for jrcagle
0
140
Member Avatar for Matt Tacular

[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.

Member Avatar for woooee
0
96
Member Avatar for sneekula

if you don't want to change list1, you can do [code] list1dup = list1[:] list3 = add_item(list1dup) ... [/code]

Member Avatar for jrcagle
0
230
Member Avatar for babutche
Member Avatar for babutche
0
1K
Member Avatar for sneekula

[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 …

Member Avatar for vegaseat
0
3K
Member Avatar for sneekula

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]

Member Avatar for vegaseat
0
106

The End.