Search Results

Showing results 1 to 40 of 51
Search took 0.22 seconds.
Search: Posts Made By: ghostdog74
Forum: Shell Scripting Apr 14th, 2008
Replies: 3
Views: 1,318
Posted By ghostdog74
don't use useless cat with while loop

while read -r line
do
#processing
done < "file"
'

anyway, here's another way to solve your problem
Forum: Shell Scripting Mar 26th, 2008
Replies: 9
Views: 2,346
Posted By ghostdog74
no need to use cat

uuencode $file $file | /usr/bin/mailx -s "TEST"
Forum: Shell Scripting Mar 7th, 2008
Replies: 8
Views: 2,562
Posted By ghostdog74
awk 'BEGIN{FS="[]].[[]|[[]|[]]"}
{
gsub(/id|\"/,"",$13)
split($3,a,"/")
gsub("tag","",$16)
print $13,a[1],$7,$16
}' file
Forum: Shell Scripting Jan 15th, 2008
Replies: 3
Views: 11,793
Posted By ghostdog74
# echo $HTML | sed 's/<html><body>\(.*\)<\/body><\/html>/\1/'
OK
Forum: Python Sep 25th, 2007
Replies: 4
Views: 3,064
Posted By ghostdog74
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.

for line in...
Forum: Python Jun 14th, 2007
Replies: 5
Views: 2,715
Posted By ghostdog74
another way

>>> for i in range(len(sentence.split()),0,-1):
... print sentence.split()[i-1],
Forum: Shell Scripting May 13th, 2007
Replies: 9
Solved: awk script
Views: 6,400
Posted By ghostdog74
yes, you can put those into a script. use loops to create a counter for your files.
eg psedocode

count=1
awk '{print NR SEP $0}' SEP="/ " exfile1.txt
for counter in the range 1 to the number...
Forum: Shell Scripting May 13th, 2007
Replies: 9
Solved: awk script
Views: 6,400
Posted By ghostdog74
you can invoke the awk script again, or just use cp,
like: cp try2.txt <newfilename>
Forum: Python May 8th, 2007
Replies: 7
Views: 1,262
Posted By ghostdog74
Personally, i would use a loop for this.

num = 32
b1 = 10
b2 = 2
x = 1
while 1:
if num%(b2**x) < num:
x = x + 1
continue
Forum: Python Mar 29th, 2007
Replies: 7
Views: 7,341
Posted By ghostdog74
it's up to you. however its good to modularize so main() is definitely good to have.
Forum: Python Mar 29th, 2007
Replies: 7
Views: 7,341
Posted By ghostdog74
you can use splitext from os module

import os,shutil
def renamer(target) :
os.chdir(target)
for filename in os.listdir('.') :
print filename
newfilename =...
Forum: Python Feb 28th, 2007
Replies: 4
Views: 1,763
Posted By ghostdog74
For your particular example, you can convert your list to a string, then find 'a'

>>> a = [(' ', ' ', [('a', 'Scott'), ('9', 'vth')]), (' ', ' ', [('a', 'Jenny'), ('9', 'vth')])]
>>> b = str(a)...
Forum: Python Feb 21st, 2007
Replies: 3
Solved: Plural of Words
Views: 3,655
Posted By ghostdog74
there are some cookbook recipe in ASPN you can refer to.
here (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82102).
they may not be wat you want, but at least will give you a head start
Forum: Python Feb 21st, 2007
Replies: 2
Solved: Word in Text
Views: 1,197
Posted By ghostdog74
you should read the docs more. also googling with "Python word count" will show you some links to what you are looking for.
Forum: Python Feb 19th, 2007
Replies: 3
Views: 6,105
Posted By ghostdog74
you can read in line by line

for line in open("file"):
if "word" in line:
do_something(line)


you can read in one whole chunk

data = open("file").read()
Forum: Python Feb 19th, 2007
Replies: 5
Views: 15,946
Posted By ghostdog74
there are several ways.
1) reading with for loop

o = open("output","a") #open for append
for line in open("file"):
line = line.replace("someword","newword")
o.write(line + "\n") ...
Forum: Python Jan 27th, 2007
Replies: 5
Solved: Scalar product
Views: 3,015
Posted By ghostdog74
Or you could do this

import operator
a = (1,2,3,4)
b = (4,3,2,1)
print sum(map(operator.mul,a,b))
Forum: Python Jan 26th, 2007
Replies: 8
Views: 3,604
Posted By ghostdog74
Do you want to include decimals like 2.0 , 2.00000 etc as a whole number ??
Forum: Python Jan 26th, 2007
Replies: 9
Views: 4,177
Posted By ghostdog74
Most string manipulation problems can be solved with Python's string functions. Only very complex ones will need regexp. So try not to use regexp if possible. Of course if you are good at it , then...
Forum: Python Jan 26th, 2007
Replies: 8
Views: 3,604
Posted By ghostdog74
you need to put a decimal before doing the division:

>>> 6.0/4
1.5
>>> 6/4.0
1.5


or you can import future:
Forum: Python Jan 26th, 2007
Replies: 9
Views: 4,177
Posted By ghostdog74
hi, wow, getter harder.:-)
anyway, here's a rather crude way and i am sure there are better ways (using re). I did substitution first, then do the rest

>>> data_raw = """
... header
... [23 ]...
Forum: Python Jan 25th, 2007
Replies: 9
Views: 4,177
Posted By ghostdog74
sorry somehow i can't find my edit button, but anyway
a decimal/float looks like this : 245.332 or 4.5 or 74.32
so to match them, we need one or more digits, followed by "." and followed by one or...
Forum: Python Jan 25th, 2007
Replies: 9
Views: 4,177
Posted By ghostdog74
another way is to use the "|" special character.

>>> re.findall(r'\d+\.\d+|\d+',data_raw)
['20', '35', '40', '84', '100', '245.99']
>>>
Forum: Python Jan 25th, 2007
Replies: 15
Solved: Sorting
Views: 2,528
Posted By ghostdog74
i think its answered in the other thread
Forum: Python Jan 25th, 2007
Replies: 15
Solved: Sorting
Views: 2,528
Posted By ghostdog74
hi there
sure, re.findall(r"(\d+)",data_raw)
thanks
Forum: Python Jan 24th, 2007
Replies: 15
Solved: Sorting
Views: 2,528
Posted By ghostdog74
assuming data is as first posted:

>>> import re
>>> re.findall(r"\[(.*)\]",data_raw)
['20 ', ' 35 ', '40 ', '84 ', '100 ', ' 245', ' 260', ' 300 ', ' 440 ', ' 521 ', ' 650 ']


...
Forum: Python Jan 17th, 2007
Replies: 6
Views: 1,900
Posted By ghostdog74
can you try :


dates = [i for i in files for j in months if j in i ]
Forum: Python Jan 12th, 2007
Replies: 7
Views: 7,138
Posted By ghostdog74
another way...but you have to test it in different cases...

lst = [11, 'Dick', 12, 'Mary', 7, 'Zoe', 9, 700, 777, 'Paul', 13456789]
slist = sorted(lst) #sort the list
min_num , max_str =...
Forum: Python Jan 11th, 2007
Replies: 6
Solved: Student GPA
Views: 2,098
Posted By ghostdog74
what is your error, and what is your expected output/results?
Forum: Python Jan 9th, 2007
Replies: 6
Views: 1,956
Posted By ghostdog74
if you don't want to change list1, you can do

list1dup = list1[:]
list3 = add_item(list1dup)
...
Forum: Python Jan 9th, 2007
Replies: 5
Views: 2,568
Posted By ghostdog74
if you just want to find "Paul" in your example, one way to do it is to convert that list to string

astring = ','.join( str(i) for i in nested_list)
if "Paul in astring:
print "Found"
Forum: Python Jan 7th, 2007
Replies: 2
Views: 1,010
Posted By ghostdog74
this is the problem

grade = input("Enter gradepoint for course (Enter to quit): ")


input() expects a number. when you just press enter, it gives error
maybe a try:except can solve the...
Forum: Python Dec 29th, 2006
Replies: 4
Views: 1,124
Posted By ghostdog74
if your lists comparing only numbers, you can sort them first?

if sorted(li) == sorted(li2):
do something
Forum: Python Dec 5th, 2006
Replies: 19
Views: 6,304
Posted By ghostdog74
def en_de_code(text,flag=0):
if flag == 0:
return ''.join([chr(ord(char) + 1) for char in text ]) #encode
else:
return ''.join([chr(ord(char) - 1)...
Forum: Python Dec 2nd, 2006
Replies: 8
Views: 5,850
Posted By ghostdog74
In Python docs first para here http://www.python.org/doc/2.4.1/lib/typesmapping.html

"""
2.3.8 Mapping Types -- classdict
A mapping object maps immutable values to arbitrary objects. Mappings...
Forum: Python Dec 1st, 2006
Replies: 2
Views: 13,250
Posted By ghostdog74
do you want to comment out "import sys" and try again?
Forum: Python Dec 1st, 2006
Replies: 4
Views: 2,484
Posted By ghostdog74
>>> a = []
>>> if a:
... print "not empty"
...
>>> b = ['a']
>>> if b:
... print "not empty"
...
not empty
>>>
Forum: Python Oct 23rd, 2006
Replies: 4
Solved: reading a list
Views: 2,211
Posted By ghostdog74
hmm.list comprehension?


alpha = [ c for c in list if str(c).isalpha()]
number = [ c for c in list if str(c).isdigit()]


if you want to get unique elements, use set
Forum: Python Oct 19th, 2006
Replies: 3
Solved: xrange() result
Views: 1,966
Posted By ghostdog74
if you look at the xrange() docs. it says "returns an ``xrange object'' instead of a list"
if you want to use xrange(). use a for loop

for i in xrange(1,5):.....
Forum: Python Sep 29th, 2006
Replies: 4
Solved: int2byte
Views: 1,088
Posted By ghostdog74
it's best if you could explain what you wish to do, give sample input and output if possible
Showing results 1 to 40 of 51

 


About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC