Search Results

Showing results 1 to 40 of 79
Search took 0.01 seconds.
Search: Posts Made By: ghostdog74 ; Forum: Python and child forums
Forum: Python Sep 24th, 2008
Replies: 4
Views: 759
Posted By ghostdog74
without glob module, just search for it

import os
os.chdir("/somewhere")
for files in os.listdir("."):
if not "_ab" in files:
print files
Forum: Python Sep 25th, 2007
Replies: 2
Views: 1,972
Posted By ghostdog74
why do you think that regular expression is the way to go?

>>> s1 =' 25000 '
>>> s1.replace(" ","")
'25000'
>>> s2 = ' 5.5910 '
>>> s2.replace(" ","")
'5.5910'
...
Forum: Python Sep 25th, 2007
Replies: 4
Views: 2,971
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,653
Posted By ghostdog74
another way

>>> for i in range(len(sentence.split()),0,-1):
... print sentence.split()[i-1],
Forum: Python May 31st, 2007
Replies: 4
Views: 5,417
Posted By ghostdog74
try not to use input(). Use the raw_input() instead. (Its documented in the docs)
Forum: Python May 31st, 2007
Replies: 3
Views: 2,277
Posted By ghostdog74
one method i always use is the os.path.join() method.

dir = os.path.join("C:\\","documents and settings","user","desktop")
starcraftpath = os.path.join(dir,"starcraft.exe")

takes care of the...
Forum: Python May 8th, 2007
Replies: 7
Views: 1,252
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 May 6th, 2007
Replies: 4
Views: 5,376
Posted By ghostdog74
if you have Python 2.4 or above,

>>> import operator
>>> serial = 12345
>>> total=[[serial,'john'],[serial,'james']]
>>> sorted(total, key=operator.itemgetter(1))
[[12345, 'james'], [12345,...
Forum: Python Apr 27th, 2007
Replies: 5
Views: 2,067
Posted By ghostdog74
if you just want to print to one output file, just do a redirect on your command prompt. eg


python yourscript.py > outfile
Forum: Python Apr 24th, 2007
Replies: 5
Views: 2,067
Posted By ghostdog74
just use the for loop to go over each item, then manipulate from there

>>> for i in alist:
... print ' '.join(map(str,i))
...
2934110 B1 D4 7C7C7C7C804040404040F140404000
2934110 5 1 1 01...
Forum: Python Apr 17th, 2007
Replies: 5
Views: 1,042
Posted By ghostdog74
if in the file, the content is indeed this:

[1,2,3,4]

then when you read the file line by line, you can use eval() to turn it into a list

for line in open("file"):
alist = eval(line)
...
Forum: Python Apr 17th, 2007
Replies: 5
Views: 1,042
Posted By ghostdog74
is this what you are looking for

>>> s = "this is a string"
>>> alist = list(s)
>>> alist
['t', 'h', 'i', 's', ' ', 'i', 's', ' ', 'a', ' ', 's', 't', 'r', 'i', 'n', 'g']
>>>
Forum: Python Apr 13th, 2007
Replies: 4
Views: 4,281
Posted By ghostdog74
import shutil,glob,os
os.chdir("wherefileis")
for FILE in glob.glob("journal*"):
shutil.copy(FILE, "someotherdir")
Forum: Python Mar 29th, 2007
Replies: 7
Views: 7,000
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,000
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 Mar 28th, 2007
Replies: 9
Views: 2,341
Posted By ghostdog74
its like this "\r\n" in DOS.
Forum: Python Mar 26th, 2007
Replies: 3
Views: 3,099
Posted By ghostdog74
OP wants to collect IP address of browser. So guess he may be using CGI. here's an example (http://www.shindich.com/sources/cgi/clientip/clientip.py)
Forum: Python Mar 26th, 2007
Replies: 2
Views: 13,622
Posted By ghostdog74
'0x' always appears in front, so if you want to use hex() and get rid of 0x, use hex(255)[2:]
Forum: Python Mar 24th, 2007
Replies: 5
Views: 2,677
Posted By ghostdog74
maybe you can try this . Not tested


def invisible():
key = ''
passwd = ''
max_char = 8
while 1 :
key = msvcrt.getch()
if key == '\r': break
Forum: Python Mar 21st, 2007
Replies: 6
Views: 2,620
Posted By ghostdog74
if you have pygame, you can use its inbuilt cdrom commands

import pygame.cdrom as cdrom
cdrom.init()
cd = cdrom.CD(0) # 0 = first cdrom device
cd.init()
cd.eject()
cd.quit()
cdrom.quit()
Forum: Python Mar 21st, 2007
Replies: 5
Views: 2,677
Posted By ghostdog74
you can use the getpass module.

import getpass
pswd = getpass.getpass("enter password: ")
print pwd
Forum: Python Mar 20th, 2007
Replies: 9
Views: 2,341
Posted By ghostdog74
a newline is represented as "\n", not "/n". maybe a typo error
Forum: Python Mar 20th, 2007
Replies: 9
Views: 2,341
Posted By ghostdog74
from where did you get this command ?
Forum: Python Mar 12th, 2007
Replies: 3
Views: 2,895
Posted By ghostdog74
Sincef you are new to python, i suggest you take the tutorial here (http://www.python.org/doc/).
Forum: Python Mar 11th, 2007
Replies: 8
Views: 3,969
Posted By ghostdog74
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,

>>> import re...
Forum: Python Mar 9th, 2007
Replies: 4
Views: 17,207
Posted By ghostdog74
s = "open sesame"
print s[0:s.index('n')] + s[ s.index('n') +1 : ]
Forum: Python Feb 28th, 2007
Replies: 4
Views: 1,719
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,519
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,191
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 21st, 2007
Replies: 1
Views: 2,003
Posted By ghostdog74
[] means an empty list in python.
Forum: Python Feb 19th, 2007
Replies: 3
Views: 5,870
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: 14,958
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 Feb 12th, 2007
Replies: 3
Views: 1,359
Posted By ghostdog74
sys.exit() implements SystemExit, see
http://docs.python.org/lib/module-sys.html
Forum: Python Jan 27th, 2007
Replies: 5
Solved: Scalar product
Views: 2,910
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,485
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,065
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,485
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,065
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,065
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,065
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']
>>>
Showing results 1 to 40 of 79

 


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

©2003 - 2009 DaniWeb® LLC