Note that you may have to append the path to the directory containing the file/module. An example of import
import sys
sys.path.append("/path/to/Car")
import Car ## not Car.py as python appends the ".py"
You can also use an indicator for wrong answers:
right_answers = True
while (abs(s1 - s2)!= 2):
x = input("Faktor: ")
y = input("Faktor: ")
z = input("Rezultat: ")
if z == x * y:
s2 = s2 + 1
print "Trenutni rezultat : ", s1, " : ", s2
else: ## assuming the above was the correct answer
right_answers = False
#
# finally
if right_answers:
print "correct or whatever"
else:
print "wrong"
# ----------------------------------------------------------------
# with a function that can be called as many times as you want
def multiply_get():
a = input("Faktor: ")
b = input("Faktor: ")
c = input("Rezultat: ")
if c == a * b:
return True
return False
'Blessings are not received twice, calamities do not occur alone.
Zen Master Wuzu
display the data using canvas
Which GUI toolkit are you using? If it is Tkinter, begin at Effbot for line drawing. Also, the polyline1 & 2 should be calculated by one function that receives the parameters and returns the number, and the same for distance1 & 2.
## pseudo-code example
def calc_poly(data):
ret_polyline = []
for ctr in range(len(data)):
ret_polyline.append(data[ctr].split(','))
return ret_polyline
polyline1 = calc_poly(data)
polyline2 = calc_poly(data2)
You are mixing strings and lists. This should help.
class Sentence:
def __init__(self, astr="I'm going back"):
self.astr = astr
def setWord(self, astr):
self.astr=astr
def getfirstword(self):
return ' Changer the word back', self.astr[2]
def getallword(self):
print "astr[2]", self.astr[2]
astr_list = self.astr.split()
print "astr_list[2]", astr_list[2]
astr_list[2] = "XXX"
print "join", " ".join(astr_list)
## self.astr[2] = "home"
return self.astr
sent = Sentence()
print sent.getfirstword()
ret_val = sent.getallword()
print type(ret_val), ret_val
You would have to return big_num. This is a modified version of the first problem, using a string to store the output. It shows passing variables. Try it and add some print statements so you know what is happening. Post back with any problems.
def main():
x = input("Enter an integer (the number of times to print): ")
y = input("Enter another integer (the number to be printed): ")
message(x,y)
print ## goto a new line
ret_str = using_a_string(x, y, "")
print ret_str[:-2] ## strip last " +"
def message(x,y):
if (x > 0):
print y, "+",
message(x - 1,y)
def using_a_string(x, y, str_out):
if (x > 0):
str_out += " %d +" % (y)
str_out = using_a_string(x - 1, y, str_out)
return str_out
main()
"z" is the same as a print statement will verify, although newx and newy do change.
for n in range(10): ## only print 10 times
print "adding math.sin(%f) to %f" % (z, newx)
newx=newx+math.sin(z)
print "adding math.cos(%f) to %f" % (z, newy)
newy=newy+math.cos(z)
print newx
print newy
##
## note that it is inefficient to calaculate sin(z) and cos(z) on every loop
##
sin_z = math.sin(z)
cos_z = math.cos(z)
for n in range(10):
newx=newx+sin_z
newy=newy+cos_z
print newx
print newy
##
## an easier way to generate choices
##
choices = [x for x in range(0, 91)]
choices += [x for x in range(270, 361)]
Pass x to the file2 function.
from file2 import *
x = 6
file2Funct(x)
##
##file2.py
##
def file2Function(x):
print x
See this link for a tutorial on input http://www.pasteur.fr/formation/infobio/python/ch04s03.html and then test the integer for >0 and <6 to break from the while() loop.
Let's create a continuing thread to program Crazy 8's from scratch for learning purposes!
DECK/CARD IDEA'S
My simple starting suggestion:
deck = ['2C','3C','4C','5C','6C','7C','8C','9C','10C','JC','QC','KC','AC', '2D','3D','4D','5D','6D','7D','8D','9D','10D','JD','QD','KD','AD', '2H','3H','4H','5H','6H','7H','8H','9H','10H','JH','QH','KH','AH', '2S','3S','4S','5S','6S','7S','8S','9S','10S','JS','QS','KS','AS',]
Start by downloading one of the existing packages, like http://duo.tuxfamily.org/lang/en/about and look at the code. If you don't understand something, then post the question and code. I don't think there are many who volunteer their time here, who want to spend it coding a solution for you when many already exist.
The book teaches Python 2.x. In Python 3.x, print is a function, so the last line would be
print(buildConnectionString(myParams))
In the future please include the actual error message, as it is almost impossible to debug when a program is larger, without knowing exactly what is wrong. Dive Into Python 3 is the only online book on Python 3.X that I know of.
As you probably have guessed by now, regular expression are considered bad style by some and so learning them is possibly a complete waste of time. If you aren't aware of Jamie Zawinski's (in)famous quote
"Some people, when confronted with a problem, think 'I know, I'll use regular expressions.' Now they have two problems."
http://regex.info/blog/2006-09-15/247
All variables in create_mail are local to create_mail and can not be used in send_mail. One solution is to use one function only, which simplifies things. See here for a starter on how to use funtions.
def create_mail(message):
themail = MIMEMultipart()
recipient = "xxxxxxx@hotmail.com"
gmail_user = "asdassdsaadssd"
gmail_pwd = "asdasdasasdasasd"
subject = "assadasdasasdass"
themail['Subject']=subject
themail['From']=gmail_user
themail['To']=recipient
themail.attach(MIMEText(message))
## comment out so everything is now part of create_mail()
##def send_mail():
smtpserver = smtplib.SMTP("smtp.gmail.com",587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(gmail_user, gmail_pwd)
print "Connection established."
smtpserver.sendmail(gmail_user, recipient, themail.as_string())
print "Your mail has been sent."
smtpserver.close()
I would start with Scripy You can also use subprocess. Doug Hellmann has a nice write-up covering input and output pipes amount other things http://www.doughellmann.com/PyMOTW/subprocess/index.html#module-subprocess
longestSentence = max((listOfWords for listOfWords in listOfSents if any(lt == word.lower() for word in listOfWords)), key = len)
#get longest sentence -list format with every word of sentence being an actual element-
longestSent=[longestSentence]
for word in longestSent:#convert the list longestSentence to an actual string
Break down the list comprehension into something readable. Perhaps splitting on the sentence break, ". ", and sending each sentence to a function which checks for the trigger word, and then returns the length of the sentence if the trigger is found, or zero if not found.
Divide by 3, multiply the result by 3, and compare to the original number, assuming that you are using integers only.
If you are looking for the same English word in both files, use one set for each file and then you can get the difference or intersection of the sets. http://en.wikibooks.org/wiki/Python_Programming/Sets To read two files, you open the first file, process it (add to the set or whatever), and then close it. Then open the second file and repeat the process http://diveintopython.org/file_handling/file_objects.html
If you are a female geek no need to read this as the odds greatly favor you no matter what you do.
"scientists at the University of Leeds in Great Britain have determined that if you want to meet the right man, the optimum amount of flesh to flash is 40%. Less than that and you might appear too dowdy to catch his eye, any more and you’re more likely to attract a stalker than a soul mate. Psychologist Colin Hendrie had his four female assistants perform demanding “undercover” surveillance in Leeds’ nightclubs, recording how women were dressed and how often they were approached on concealed dictaphones. But it wasn’t just the women who were being judged. Hendie’s results also showed that the most successful approaches came from men who were neither too thin nor too fat and at least a head taller than their target. It also revealed that 30% of clubbers left as couples, though only 20% arrived so" (Daily Mail).
Use root.withdraw
from tkinter import *
##from tkinter import ttk
from tkinter import messagebox
root = Tk()
root.withdraw()
answer = messagebox.askyesno(message="Are you thinking of the " + "data " + "?"
,icon='question' ,title="My guess")
print(answer)
Does everyone know about Doug Hellmann's Python Module Of The Week. A good source for basic learning.
http://www.doughellmann.com/PyMOTW/threading/index.html#module-threading
http://www.doughellmann.com/PyMOTW/about.html
There are so many examples on the web that I doubt anyone will respond. Try this link http://lmgtfy.org/?q=tkinter+update+time
The problem you pointed out, woooee, wasn't actually a problem. It recognizes both sticky=E and sticky="e" as valid, and they both work in exactly the same way.
E is recognized if you do a
from tkinter import *
which you can not rely on as normally "import tkinter" is used in my experience, especially if you are modifying someone else's code, and you are betting that E was not declared as a variable somewhere else in the program. "e" is always a good bet. Effbot's grid doc is a good reference http://effbot.org/tkinterbook/grid.htm And consider a function for all of those labels, passing the text, row, column, etc. to it. The same for the entry boxes, or one function to create the label and entry since entry column is always label column+1.
Try adding some print statements as below.
def file1(filename):
d1 = dict()
fp = open(filename)
for line in fp:
print "processing file1 line =", line
process_line1(line, d1)
return d1
def file2(filename):
d2 = dict()
fp = open(filename)
for line in fp:
print "processing file2 line =", line
process_line(line, d2)
return d2
Pass the class instance to the GUI program. An example with all classes in the same program.
import random
class GUIClass:
def __init__(self, class_instance):
# create a text area named "textArea"
# bind the function "OnEnterDown" to the Enter key
self.ci = class_instance
print self.ci.my_number, self.ci.my_word
print "\n calling on_enter_down() within the class"
self.on_enter_down()
def on_enter_down(self):
# Call the function 'combine' in MyScript.py
self.ci.combine()
class MyClass:
def __init__(self):
self.my_number = random.randint(1, 10)
self.my_word = "Hello"
def combine(self): # I want this function to be called when the Enter key is pressed
phrase = "%s %d" % (self.my_word, self.my_number)
print phrase
MC = MyClass()
GC = GUIClass(MC)
print "\n calling on_enter_down() outside the class"
GC.on_enter_down()
I would suggest that you print Dictionary to make sure that it is in the form you require. You only read the Search file one line at a time:
Dictionary = set(open("e:/assignment/dictionary.txt"))
print Dictionary
SearchFile = open(input("Please Enter a File Path: "))
WordList = set() ## WordList is a set not a list
for line in SearchFile:
line = line.strip()
if line not in Dictionary:
WordList.add(line)
print(WordList)
Take a look at the Python Style Guide when you have time http://www.python.org/dev/peps/pep-0008/ The variable name conventions make it easier for others to understand your code. Also include your code in code blocks the next time (the # symbol at the top) as indentation is significant in Python.
The idea is for the python - tk-inter window to pop up just after boot up and start its routine.
There is no GUI until X is started so no Tkinter (you may be able to use TCL or Curses depending on when you run it), so you should add the program to ~/.xinitrc or to the ~/xfce startup script. I use fluxbox so am not sure what the startup script is
http://www.associatedcontent.com/article/2909956/earthquakes_caused_by_loose_woman_and.html "The Ayatollah Kazem Sedighi related to a group of worshipers in Tehran, Iran what actually causes earthquakes. The cause is not, as one would have suspected having been deceived by infidel science, the movement of tectonic plates.
No, the Ayatollah Kazem Sedighi revealed that earthquakes, at least in Iran, is caused by loose women who dress like tarts. "
And a co-worker wonders what causes volcanoes.
A line is more than a single point if you are trying to code a line. I don't know. You didn't say. But if you want a bar graph for example then you have to code for a bar, see this example from the matplotlib docs http://matplotlib.sourceforge.net/examples/pylab_examples/barchart_demo.html Take a look at Ene's example here as well http://www.daniweb.com/code/snippet216915.html I'm outta here. Your descriptions are too vague and I'm sorry, but don't have the time to try and intuit what it is you are trying to do.
What i am trying to do is take the list of strings, which must be of equal length, and use a nested for loop to go over each character and its neighbours for creation of the relevant equations.
This solution is similar to a tic-tac-toe game, except the board can be any size. One way to do it is to index a dictionary using a tuple containing the row & column number. The neighbors then would be a row, column tuple for row+1, row-1, col+1, and col-1.
shape=[
' ',
'++++',
'xxxx',
'xxxx',
'xxxx',
'----',
' ']
shape_dict = {}
for row, rec in enumerate(shape):
for col, ch in enumerate(rec):
shape_dict[(row, col)] = ch
print shape_dict[(2,2)] ## print one as an example
You should use Python's sort() function for lists. In any case, "doesn't work" is not descriptive enough. Include some test input, your output, and the desired output if you want to write the sort code yourself.
In addition to what Gribouillis said, you have it backwards. (Please don't use "i", "l", or "o" as single digit variables as they can look like numbers.)
for j in range (len(myList-1)):
for k in range (j+1, len(myList)):
Check itertools' product.
import itertools
list_1 = [1, 2, 3]
list_2 = [4, 5, 6]
x = itertools.product(list_1, list_2)
for y in x:
print y
""" My result
(1, 4)
(1, 5)
(1, 6)
(2, 4)
(2, 5)
(2, 6)
(3, 4)
(3, 5)
(3, 6)
"""
Do not use things you do not understand. You may fix this error, or you may just make the error more subtle. You have no way of knowing since you don't understand it. This code has everything that you shouldn't do. And is probably done by a lazy coder. Pass the variable back and forth or learn to use classes (or spend the rest of your life beating your head against this wall).
def a_function_with_a_name_that_has_some_meaning(psyc_stat=False):
print psyc_stat
psyc_stat = not psyc_stat
print psyc_stat
return psyc_stat
ps = a_function_with_a_name_that_has_some_meaning()
print "-" * 10
ps = a_function_with_a_name_that_has_some_meaning(ps)
"""
My Results
False
True
----------
True
False
"""
File "C:\Python26\getcard.py", line 22, in giveCard
It appears the error is in getcard.py, which you did not post, and not in testmod.py which you did post. The code you posted worked fine for me. BTW the following will only work for self.Tcard == 11, not if it equals 12 or 13.
if(self.Tcard <= 11 & self.Tcard != 14):
=================
if(self.Tcard == 11):
self.Tcard = "J"
if(self.Tcard == 12):
self.Tcard == "Q"
if(self.Tcard == 13):
self.Tcard == "K"
self.Sum+=10
#
##----- a dictionary would work better than multiple if statements
card_dict = [ 11:"J", 12: "Q", 13:"K"}
if self.Tcard in card_dict:
self.Tcard = card_dict[self.Tcard]
Finally, take a look at the Python Style Guide when you have time. It is easier to debug other people's code when we all use the same conventions http://www.python.org/dev/peps/pep-0008/
You can not mix canvas and grid. To use a label, button, etc. you must add a frame to the canvas. The following example will get you started on this, as well as using a for loop to create the square.
##------- Do not import Tkinter twice; use one or the other
from Tkinter import *
##import Tkinter as tk
def startMenu():
top_tk = Tk()
top_tk.title("Checkers")
top = Canvas(width="800", height="800")
square_list = []
color = "white"
for j in range(0, 701, 100):
square_list.append(top.create_rectangle(j,0,j+100,100, fill=color))
if color == "white":
color = "black"
else:
color = "white"
fr = Frame(top, relief=GROOVE, borderwidth=2)
label1 = Label(fr, text='Checkers', font=('Arial', 36), fg="blue")
label1.pack(side="left")
top.create_window(210, 800, window=fr, anchor=SE)
top.pack(fill='both', expand='yes')
top.mainloop()
startMenu()
Do it in one pass by converting to a dictionary of lists which can then be copied to the file.
test_list = [
{'item1':3, 'item2':3, 'item3':5},
{'item1':2, 'item2':6, 'item3':3},
{'item1':18, 'item2':12, 'item3':1} ]
redone_dict = {}
for dic in test_list:
for key in dic:
if key not in redone_dict:
redone_dict[key] = []
redone_dict[key].append(dic[key])
print redone_dict
Your indentations are not correct, and you want to do something else if no files are found. And this is the most that I am willing to do to clean up the screwy tabs and spaces in the code so I hope it is legible.
def open_file():
if '.trv' in os.listdir(os.getcwd()):
print "Which trivia episode would you like? It must have a .trv extension:"
print os.listdir(os.getcwd())
print "Type in the correct file name: "
file_name = raw_input()
"""Open a file."""
try:
the_file = open(file_name, 'r')
except(IOError), e:
print "Unable to open the file", file_name, "Ending program.\n", e
raw_input("\n\nPress the enter key to exit.")
sys.exit()
else:
return the_file
else:
print "There are no files in this directory"
return
It depends on whether you want to find sub-words or not. The simple example below shows the difference.
words_master = [ "the", "there", "theres"]
##--- look for word in list
word = "there"
if word in words_master:
print(word, "found")
else:
print(word, "Not found")
##--- compare each word in the list to the original word
print("-"*30)
for m_word in words_master:
if m_word in word:
print("%s found in %s" % (m_word, word))
This line does nothing
if len(modified) == 0 : continue
Look at the second word of the *new* list. If it does not contain
"trunk" or "branches", skip the line. (stuck on this)
Use the "in" keyword.
**--- will return a positive for words like "strunk"
found = False
for word in ["trunk", "branches"] :
if word in words[1]:
found = True
if not found:
print "processing this"
For testing, cut the list down to 10 or 20 hex's and enter a value within that range. You are testing, so you want results in a reasonable amount of time. Also, note that some values are still missing. The following code will print the missing values. It can also be modified to generate the list instead of keying it manually.
charset = [
'01', '02', '03', '04', '05', '06', '07', '08', '09', '0b', '0c',
'0e', '0f', '10', '11', '12', '13', '14', '15', '16', '17', '18',
'19', '1a', '1b', '1c', '1d', '1e', '1f', '20', '21', '22', '23',
'24', '25', '26', '27', '28', '29', '2a', '2b', '2c', '2d', '2e',
'30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '3b',
'3c', '3d', '3e', '41', '42', '43', '44', '45', '46', '47', '48',
'49', '4a', '4b', '4c', '4d', '4e', '4f', '50', '51', '52', '53',
'54', '55', '56', '57', '58', '59', '5a', '5b', '5c', '5d', '5e',
'5f', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69',
'6a', '6b', '6c', '6d', '6e', '6f', '70', '71', '72', '73', '74',
'75', '76', '77', '78', '79', '7a', '7b', '7c', '7d', '7e', '7f']
k_range = [ str(x) for x in range(0, 10) ]
k_range.extend(['a', 'b', 'c', 'd', 'e', 'f'])
print k_range
for j in range(0, 8):
for k in k_range:
x = str(j) + k
if x not in charset:
print x
If you want to be sure that you only sample the same three values once, then you will have to keep track of the threesome somewhere, as each individual value could be used in another threesome. I don't know how many possible 4 digit permutations, randomly associated in triples there are, but it is a lot and probably would require more computing power than you have. You might want to consider testing for one group of the three at a time. That is, break the value you are testing against into it's component parts and find each one individually. Even better would be testing for the one-twelfth, each hex, individually. That should reduce the time from months to minutes. Finally, note the the "while True" loop never ends.
With some luck your department will publish a list of school holidays and then you can transfer it easily to a list of (month, day) tuples for the year, or the dictionary Gribouillis suggested.
Ah yes. The simplest solution is the best. And there is probably a web page that can be traversed, making it even easier.
There is SpecTcl and VisualPython (3D) as well, but is anyone going to use a 'visual' front end to Tkinter. It is easier to generate your own code IMHO.
What about floating holidays like Easter, (Easter falls on the first Sunday after the first full moon after the spring equinox unless the full moon is on the equinox in which case it is after the following full moon), and Thanksgiving, which is easier but still not a specific date. Also, President's Day is usually celebrated (=some people get it off) on the Monday between Lincoln's and Washington's birthdays. So you will have to allow for some calculations. The simplest to digest would be one dictionary with actual dates, and a second dictionary with known symbols that can be used to calculate the date, 4Th-11 would be the fourth Thursday in November for Thanksgiving. For Easter, you would have to access a web site like NOAA'S to get the equinox and full moon, and that would probably be a separate function so not in any dictionary.
Python uses references to point to a list, so you can use lists to do what you want. A linked list is one method used to do this depending on the specifics.
AllAtoms = {}
AllAtoms[0] = [0,[]]
AllAtoms[1] = [0,[AllAtoms[0]]]
AllAtoms[2] = [0,[AllAtoms[0]]]
print "Original"
for item in AllAtoms:
print item, AllAtoms[item]
print "-"*50
AllAtoms[0].append(9)
for item in AllAtoms:
print item, AllAtoms[item]
##----- OR -------------------------------------------------
print "-"*50
AllAtoms = {}
AllAtoms[0] = [[0],[1]]
AllAtoms[0][0] = [9]
AllAtoms[1] = [0,[AllAtoms[0]]]
AllAtoms[2] = [0,[AllAtoms[1]]]
for item in AllAtoms:
print item, AllAtoms[item]
#
#----- My Output
0 [0, []]
1 [0, [[0, []]]]
2 [0, [[0, []]]]
--------------------------------------------------
0 [0, [], 9]
1 [0, [[0, [], 9]]]
2 [0, [[0, [], 9]]]
--------------------------------------------------
0 [[9], [1]]
1 [0, [[[9], [1]]]]
2 [0, [[0, [[[9], [1]]]]]]
Once you read a file, that is it, unless you go back to the beginning and start over again, so after the first pass, g.readlines() does nothing. Instead, I think it is save to store the whopping 15 lines in memory as a list and iterate over the list. In the future, you want to develop the habit of adding print statements to debug, which would show that nothing was happening after the first pass through the 'f' for() loop.
for line in f.readlines():
for ln in g.readlines():
#
#---------- replace with
g_data=open(self.dcmdir+"/DOPEN/extlib.ded",'r').readlines()
f_data=open(self.dcmdir+"/DOPEN/dwnext.ded",'r').readlines()
for line in f.data:
for ln in g_data():
Using list insert may indeed be slower that string concatenate, since every item after the inserted one has to be moved. This is why I chose to create at list of zeroes first and then extend it using the hex value. It depends on the length of the string or list, of course. These times are going to be longer because functions are called. And timeit extends the execution time considerably.
import timeit
n = 500
def test_extend():
test_list = [ 0 for x in range(n)]
test_list.extend('ff12')
def test_insert():
x = ["ff12"]
for ctr in range(n):
x.insert(0, '0')
def test_string():
x = 'ff12'
for ctr in range(n):
x = '0' + x
print( "test_extend took %0.3f micro-seconds" % (timeit.Timer(test_extend).timeit()) )
print( "test_insert took %0.3f micro-seconds" % (timeit.Timer(test_insert).timeit()) )
print( "test_string took %0.3f micro-seconds" % (timeit.Timer(test_string).timeit()) )
"""
##--- insert 5 zeroes
test_extend took 3.241 micro-seconds
test_insert took 3.174 micro-seconds
test_string took 1.683 micro-seconds
##------- insert 500 zeroes
test_extend took 46.459 micro-seconds
test_insert took 330.859 micro-seconds
test_string took 117.718 micro-seconds
"""
For starters, you can use a dictionary and a list in the Card class. Test each class and function individually, whether it is in a class or not, before you include it your main program so you know that it works properly and returns the correct value. You obviously have too large of a program here for you to be able to debug.
class Card:
def __init__(self, suit, rank):
self.card_dict = {}
self.card_dict[1] = ["Ace", 11]
self.card_dict[11] = ["Jack", 10]
self.card_dict[12] = ["Queen", 10]
self.card_dict[13] = ["King", 10]
self.suit_list = ["*", "Clubs", "Spades",
"Diamonds", "Hearts" ]
def rank_suit(self, suit, rank):
if rank in self.card_dict:
self.value = self.card_dict[rank][1]
self.cardname = "%s of %s" % \
(self.card_dict[rank][0], self.suit_list[suit])
else:
self.value = self.rank
self.cardname = "%s of %s" % \
(str(rank), self.suit_list[suit])
Try
line = line.strip() ## instead of line = line[:-1]
or make sure there is a return/newline in the last line of the file.
First, don't use "file" as a variable name as it is a reserved word. I would guess that the problem may be with counter equal or not equal to one, or not stripping spaces from the name or term. There were some punctuation errors in the code you posted as well. The following code, using test data, seemed to work for me with the above errors corrected. Finally, "fileappender" is unnecessary and slow in that you have to open and close the file each time. Just return the file pointer from the open() and use it to write.
def filereader (filename):
""" commented -- using test data
fp = open(filename ,'r')
text = fp.readlines()
fp.close()
"""
text = ["fname1, term1", "fname2, term2", "fname3, term3" ]
return text
def filewriter (filename, text):
fp = open(filename ,'w')
return fp
# file.writelines(text)
# file.close()
resultsfile = 'C:\\resultsfile.txt'
fp_out = filewriter(resultsfile)
fp_out.write("Results File \n")
notes = filereader('C:\\mainlist.txt')
readfile_test = [ ["term1", "term4", "term1"],
["term1", "term2", "term1"],
["term1", "term4", "term3"] ]
ctr = 0
for item in notes:
print "Line: " + item
substrs = item.split(",")
fname = substrs[0].strip()
print "File: " + fname
term = substrs[1].strip()
print "Term: " + term
fp_out.write("File : %s\n" % (fname))
fp_out.write("Error: %s\n" % (term))
##--- use test data
readfile = readfile_test[ctr]
ctr += 1
# readfile = filereader(fname)
#print readfile
counter = 0
for subline in readfile:
print "subline:" + subline
if counter == 1:
fp_out.write( " %s\n" % (subline))
print " c0sub: " + subline
counter …
Works fine for me (using the following stripped down version). You should include the actual error when posting; it is not always what you think it means.
class Card():
SUIT = { 'C':'Clubs', 'D':'Diamonds', 'H':'Hearts', 'S':'Spades' }
VALUES = { '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, \
'10':10, 'J':12, 'Q':13, 'K':14, 'A':15 }
def __init__(self):
print("Card class instance")
class PokerHand():
SIZE = 5
RANKS = { 0: "Straight Flush", 1: "Four of a Kind", 2: "Full House", \
3: "Flush", 4: "Straight", 5: "Three of a Kind", \
6: "Two Pairs", 5: "Pair", 6: "High Card" }
def __init__(self):
print("PokerHand class instance")
print("From PokerHand")
self.issflush()
def issflush(self):
print(Card.VALUES)
PH = PokerHand()
print("\nFrom main")
print(Card.VALUES)
print("\nissflush")
print PH.issflush()