lllllIllIlllI 178 Veteran Poster

Steve's code is almost right :)
The problem is in line 5

line.replace('.','')

The problem with that is that it doesn't store the new string in the variable automatically, so just add a line = in front of that and it should be fine:

file1 = open('words.txt', 'r')
file2 = open('output.txt', 'w')
file1_cont = file1.readlines()
for line in file1_cont:
    line = line.replace('.', ' ')
    file2.write(line)

Hope that helps :)

lllllIllIlllI 178 Veteran Poster

All that the .pyw extension does that the .py doesn't is make that black window "python.exe" not show up, which is useful for wxPython apps, sometimes :P

lllllIllIlllI 178 Veteran Poster

Okkay. Then what i would do is rather than just saying

open("names.txt")

I would do the full address of where i put the file so

open(r"C:\Program Files\Wing IDE 101 3.2\src\debug\tserver\names.txt")

And that should find it then :)

lllllIllIlllI 178 Veteran Poster

And also change the like

app.Mainloop()

to

app.MainLoop()
lllllIllIlllI 178 Veteran Poster

Okay so you need to just copy the names file into

C:\Program Files\Wing IDE 101 3.2\src\debug\tserver\

lllllIllIlllI 178 Veteran Poster

Could you post the exact error? That can help a lot.

As well there are a few things you need to address.

def name_list():
    infile = open('names.txt', 'r')
    names = infile.readlines()
    infile.close()
    index = 0
    while index < len(names):
        names[index] = names[index].rstrip('\n')
        index += 1
    return names

When you have return names it doesn't actually do anything as in the main function you do not store the returned value in a variable. So in that case you should do something more like

def main():
    names = name_list()
    print_list()
    write_output()
    search_list()

Now the returned value will be stored in names..

well hopefully that helps a little :)

lllllIllIlllI 178 Veteran Poster

You can find out how something is make up by using the dir() function.

This lists all of the variables, methods and classes of whatever you put inside the brackets :)

lllllIllIlllI 178 Veteran Poster

Well you can use the type() function to show what type the number is:

>>> type(12)
<type 'int'>
>>> type(12.4)
<type 'float'>
>>> type(input())
12
<type 'int'>
>>> type(input())
12.5
<type 'float'>
>>>

So you can adapt that to check for any type. So when you input something you can do something like

#Keep pass as False until they have entered an integer :)
cont = False

while not cont:
    i = input("Enter input (integers only):")

   #This checks if the type of the input is equal
   # to the int type. Just as we saw above
    if type(i) == int:
        #If it is then the loop can stop and the program can continue
        cont = True

Hope that helps :)

lllllIllIlllI 178 Veteran Poster

If you are using python 3 then you just have to change your input and print statements to fit

order=int(input("Please enter the price of the order: "))
x=1.50
if order <10:
    print("the total price including the delivery charge is", order + x)
else:
    print("The toal price including delivery charges is", order)

HTH :)

lllllIllIlllI 178 Veteran Poster

Sooo. What work have you done? Its nice to see a base from which we can help you.

lllllIllIlllI 178 Veteran Poster

A lot of developers aren't bothering changing their modules to 3.x I dont upgrade personally because i know if i do i will not be able to use wxPython anymore :(

So yeah, also seeing the last newspost was almost a year ago i have a feeling its not that active anymore... But heh, i could be wrong

lllllIllIlllI 178 Veteran Poster

http://xkcd.com/297/
Sorry, i dont usually link things. But this feels appropriate :)

lllllIllIlllI 178 Veteran Poster

If you want to write something at the start of a file though you would need to do something like this

#opening the file in read ("r") mode
f = open("file.txt",'r')
#get all that is in the text file so far
oldString = f.readlines()
#and close it
f.close()


#delete it so we can reopen the file in write mode ('w')
del f
f=open("File.txt",'w')

#the string we are adding
newString = """
Hello
This will go
At the start"""

#writing the new string

for line in newString.split("\n"):
    f.write(line+'\n')

#writing the old string
for line in oldString:
    f.write(line+'\n')

#closing the file

f.close()

That is untested code.. so im not quite sure how it will work, but hopefully it shows the concept i am trying to show :)

hope it helps :)

lllllIllIlllI 178 Veteran Poster

Yes you would increase that, but you would also need to completely redraw the whole circle. As well as that you would need to clear the last circle.

lllllIllIlllI 178 Veteran Poster

A static method is one that can be called without instantiating the class
so

>>> class T(object):
	def test():
		print "HI"

		
>>> T.test()

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    T.test()
TypeError: unbound method test() must be called with T instance as first argument (got nothing instead)
>>>

See how that doesnt work? Well we can make it work by making it into a static method

>>> class T(object):
	@staticmethod
	def test():
		print "HI"

		
>>> T.test()
HI
>>>

So, hopefully that shows what it does :)

lllllIllIlllI 178 Veteran Poster

When im bored I go on Daniweb ,of course!

You must get bored *a lot* :P

lllllIllIlllI 178 Veteran Poster

Why do people limit themselves to the PC only sometimes?

Haha exactly, i try and make my gardening as edible as possible personally. My strawberries are my favourite. :P

But good luck with piano, i have been playing ever since i was 5. Doesn't mean i'm that good :P but i still have soo much fun.

EDIT: WOoo 800 posts :)

lllllIllIlllI 178 Veteran Poster

If i am that bored i go and garden. Or practice piano :)

lllllIllIlllI 178 Veteran Poster

Yes, i think that is what they are trying to do, but at daniweb we try to not give outright answers for the questions and rather steer users in the right direction so that they may learn by themselves :)

lllllIllIlllI 178 Veteran Poster

Have a fiddle around with

count = 0

while count <= len(s)+2:
    count +=1
    print '*'

That should print out that right amount of asterisks. See if you cant take that a bit further :)

lllllIllIlllI 178 Veteran Poster

If you want a book that explains it all really nicely, and is free then have a look at Dive into Python:

FOR PYTHON 2.*
http://diveintopython.org/toc/index.html

FOR PYTHON 3.*
http://diveintopython3.org/

It is the best book i have read on python, and if you really like them you can buy hard copies. :)

lllllIllIlllI 178 Veteran Poster

If by unparsed HTML via script you mean get the source code for a page. Then you do that by using urllib

import urllib

#This is a file like object. 
data = urllib.urlopen("www.daniweb.com")

#So we have to read() it to get the text
print data.read()

Hope that is what you meant :P

SoulMazer commented: Very helpful and follows through +2
lllllIllIlllI 178 Veteran Poster

have a look at Beautiful Soup:

I have heard that it is an excellent tool for scraping webpages.

If that doesn't work then you can always try using string methods...

text = "<tr colData0='Friday'>"
#Split into a list with 3 items.
text = text.split("'")
print text[1]

Actually, the second idea would probably be the simplest :P

lllllIllIlllI 178 Veteran Poster

There are a great many prime number generators in the code snippet sections :)

http://www.daniweb.com/code/forum114.html

Otherwise, i would look at techniques to find primes. Then come back with some code if you have any issues.

Here is a great idea http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

lllllIllIlllI 178 Veteran Poster

BTW, have you thought about how your going to get the username and password out of the TextCtrl?

It shouldn't be to hard, have a look at the API for the wx.TextCTRL
http://www.wxpython.org/docs/api/wx.TextCtrl-class.html
One of the functon is GetValue() that returns a string of the value in the textctrl, simple :)

lllllIllIlllI 178 Veteran Poster

Should you decide to have fun with Python, be aware that the language has been modernized starting with version 3. I would recommend to start with the present version Python 3.1.1

Yeah as he said, wxPython has not been made for python 3.
The versions that have wxPython support are:

  • Python 2.4
  • Python 2.5
  • Python 2.6

So personally i do not use python 3 for the reason that i use GUI's in almost every program.

lllllIllIlllI 178 Veteran Poster

Yeah i definitely agree. Matlibplot is great.
Here is a simple tutorial for you to start out :)
http://matplotlib.sourceforge.net/users/pyplot_tutorial.html

Oh and this is where you download it from
http://matplotlib.sourceforge.net/

lllllIllIlllI 178 Veteran Poster

Just found this bug when going to the social groups page.

Running google chrome 3.0
windows 7

Also, what is the point of social groups? Is that just like an easy place to have a sub-forum?

lllllIllIlllI 178 Veteran Poster

No. Because its hard to read code (especially python) without code tags

import re

infileName1 = raw_input("Enter filename ")
infile1 = open(infileName1, 'r')
data1 = infile1.readlines()
outfile = open("test.txt", 'w')

for line in data1:
    parameters = line
    if re.search("KEYWORD",line):
        count = 1
        for i in range(count):
            outfile_temp.write(parameters)

So to solve this we first need to get around how to skip four lines ahead after finding the keyword. We shall do this by enumerating. This is used so that every loop of the 'for line in data1' it will also have a number of how many times it has looped. Great for knowing how many lines you have gone through.

So

for index, line in enumerate(data1):
    #now index is the line it is on, line is still just the same as before

Now we need to skip four lines and keep the code going

so

#we could do something like this
    if re.search(KEYWORD, line):
        index += 4
        #and then we just read the index of the file, that way we get the line 4 places ahead of where the loop is at
        #but we still need to find n!
        n = int(raw_input("Enter n"))
        for f in range(n):
            print(data1[index])

Now i have started you off, try and put it together and try starting the file writing bit.

Hope that helps :)

lllllIllIlllI 178 Veteran Poster

Yeah i was the same as kaninelupus until 2 hours ago when i got a flood of emails coming through.. :)

P.S. Woot! 700 posts!

Ancient Dragon commented: Congrats on your 700 post milestone :) +36
lllllIllIlllI 178 Veteran Poster

In every class in the __init__ method you have to put

threading.Thread.__init__(self)

Without this threading with classes just dosent work properly.

So for example

import threading

class Test(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
    def run(self):
        #dostuff
T = Test()
T.start()

Hope that helps

lllllIllIlllI 178 Veteran Poster

If your on windows there is a great way to tell what a process is. I cant quite remember how to do it on a *NIX system. But you go CTRL+ALT+DEL and then go to the processes tab, you will see a whole lot of processes, all of the programs running on your computer.

But in each of these processes there can be threads. So a thread is a process inside a process. Generally you make spawn new processes when you are launching another application or something similar and use threading for most other things.

lllllIllIlllI 178 Veteran Poster

Your code has a couple of issues, if i am not wrong it will not actually start using threading with your code as it is. You need to add a couple of lines

class Thread ( threading . Thread ):
        def __init__(self):
            threading.Thread.__init__(self)

	def run ( Self ):
		subprocess . call ( "mycommand.exe" )

See how i have called the __init__ method on the threading.Thread class? This means that now it will run the __init__ method of the Thread class, which is needed for threading to work properly with classes.

So try replacing you current class with that and try again and see how it all goes :)

Hope that helps

shadwickman commented: Ah, good point. I missed that! :D +4
lllllIllIlllI 178 Veteran Poster
def eliminate( grid, square, value ):
    row = square[ 0 ]
    col = square[ 1 ]
    poss = grid[ row ][ col ]
    if len( poss ) > 1:
        poss.remove( value )
    grid[ row ][ col ] = poss
    # if len( poss ) == 1:
    # fixValue( grid, square, poss[ 0 ] )

I think i got the indentation right :P

And can you do a printout of what the list 'grid' looks like? That might be able to help, just one grid though. Not every one.

lllllIllIlllI 178 Veteran Poster

Well you can write a tab by using the escape character and t. So if you were writing a tab to a file you would go something like this:

f = open("File.txt",'w')
f.write("\t This will be indented one tab space!")
f.close()

So the \t is the escape sequence used to indicate a tab.

Hope that helps :)

lllllIllIlllI 178 Veteran Poster

ooh my bad :S.

lllllIllIlllI 178 Veteran Poster

what i would do is read the whole file into one list, then you can do something like:

#open it, it is automatically in read mode
f = open("dnalookingfile.txt")

#get a list with all the lines
lines = f.readlines()

#iterate through the lines
for line in lines:
    if "rs" in line:
        #delete this one from the lines list and the next one as well
    else:
        #its all good, the line does not have rs numbers in it

Then you could just rewrite the file after you are done and it would be fixed :)

Hopefully :P

lllllIllIlllI 178 Veteran Poster

Yeah, i dont know if you may have checked this. But i know i stuffed this up one time, but are you sure its .jpeg not .jpg or .JPG or something like that?

:P

lllllIllIlllI 178 Veteran Poster
self.Bind(wx.EVT_MENU, self.Close(), id=ID_FILE_QUIT)

Theres ya problem!
You dont need to put the brackets after self.Close, the brackets are only used if you actually want to call the function, so take out those brackets and try again. That hopefully should fix your dilemma.

:)

lllllIllIlllI 178 Veteran Poster

I always use the wxPython api when i want to find something out, its a very very useful skill to be able to do that, because of the lack of documentation you really have to try and use what you do have.

I once wrote a small explanation on wxTextCtrl, ill attach it to the post, its a pdf. One bit of it goes over the side of the page, sorry bout that :P

Hope it helps

lllllIllIlllI 178 Veteran Poster

Yeah i agree, i think the best that you could do was boot into windows or something and then just start you new 'python OS' being a fullscreen gui that can do things that you want it to.
But as for an actual os, it is impossible as python isnt low-level enough and needs an interpreter.

lllllIllIlllI 178 Veteran Poster

It is used when using formatted strings.
I could try explain, but a great book has been written and has a bit about it :)
http://diveintopython.org/getting_to_know_python/formatting_strings.html

Read and enjoy the best free book on python imho

hope that helps

lllllIllIlllI 178 Veteran Poster
self.Bind(wx.EVT_BUTTON, self.UpdateNebula(), self.Update_Nebula)

This will not work, you are actually calling the fucntion self.UpdateNebula when you put the parentheses there, so if you get rid of them you will be fine :)

Another way i do it a lot is just to bind them to the objects themselves:

self.Update_Nebula.Bind(wx.EVT_LEFT_DOWN, self.UpdateNebula)
#this will bind it to the same as if you did the previous code, i just find it has less issues

But its really up to your own taste what you want to do.

lllllIllIlllI 178 Veteran Poster

if you have a list its as simple as calling the sort() method

li  = ['a','h','w','j','s','r','y']
li.sort()
print li
lllllIllIlllI 178 Veteran Poster

Just a quick note. The above code will work if you change all of the instances of "sys" to "os"

SO it will look like

import os
os.system("shutdown -s")

Hope that helps :)

lllllIllIlllI 178 Veteran Poster

Also, when i import things i get a syntax error if i have brackets in my import. So that might be it, seeing as it looks like its trying to import
NumberStimuliGenerator(revised). Personally i would change the file's name to something without brackets. Seeing as in python, they usually mean a tuple or function!

Hope that helps

lllllIllIlllI 178 Veteran Poster

lol. i didn't realize til today that the tutorials i've been watching are paulthom's tutorials. thanks!

Oh God, those things. They are so embarrassing, not the content so much as my voice, they were all done just before my voice broke. So i am a puny little kid it sounds :$

lllllIllIlllI 178 Veteran Poster

I use the Chrome Beta and that works a charm.

lllllIllIlllI 178 Veteran Poster

Wow, i must say i am impressed. A lot of people just sit around lazily for answers, its great that your pursuing them yourself. It will certainly lead to you learning a lot faster ;)

lllllIllIlllI 178 Veteran Poster

Then you will probably use something called recursion.
That is when a function calls itself. It is used in these kind of situations.

def recurse(num,count):
    if count == 10:
        return
    else:
        print num/2
        recurse(num/2, count+1)

recurse(100.0,1)

See, the recursive function has something called a base case. That is something that the recursive function knows what to do with and can stop recursing. So in this case our base case is that if the count is equal to ten then the function will return, therefore returning to the previous function. That in turn returns to the function it was called from up till the top one. But if it does not match the base case we print our new result and continue with recursion.

Hope that helps

EDIT: I made it 100.0 so that it would use decimal places where necessary.

sneekula commented: nice example +8