woooee 814 Nearly a Posting Maven

To print directly to the printer, you have to access the device driver. I'm on linux so can't help you there. A more common method for simple files that do not have to be formatted is to write the output to a file and use os.system() or subprocess with a system call to print the file. In linux it is
os.system( "lpr filename")
In the dark ages when I used to use Windows it was just "print full_path_filename" which if it works it all the time you have to spend on this. The print command (if there is one) may also have an option to add line numbers when you print. Google should help you find more if no one here can be of more help.

woooee 814 Nearly a Posting Maven

I figured it out, thanks for the help guys!

I hope you will test the code you posted if that is your final version.

Here's the correct Python:
>>> factors(54)
[1,2,3,6,9,18,27,54]

The number one is not usually included as a factor since it is a factor of all numbers. The same is true for the number itself. The OPs for loop is
for x in range(2, int(n**0.5)+1):
as it should be. The loop starts at 2, which we want in order to eliminate the number one, and ends with n**0.5+1 which is all the farther you have to go, and that also eliminates the number itself. A prime number should return an empty list, since it has no factors.

woooee 814 Nearly a Posting Maven

The assignment says "For a number n, this function determines all factors of n and returns these factors as a list" so I would assume that the number 54 would return (2, 3, 6), and their other half (27, 18, 9) as a list, meaning the program would want to use all of the even numbers up to n**0.5. It would return an empty list of length zero if the number is a prime number.

woooee 814 Nearly a Posting Maven

Setting a path is OS dependent. In Linux you should be able to use os.system( "export NEWPATH" ) although I haven't tried it. If you want to import a module that is not in your PYTHONPATH then you can use sys.path.append(). Almost every tutorial covers this.

vegaseat commented: nice help +7
woooee 814 Nearly a Posting Maven

You can replace the for loop with a function to do this using recursion. While this board will help with homework, not many here will do the whole thing for you.

woooee 814 Nearly a Posting Maven

Obviously exp() can't use an array as input. This makes sense. I suggest you ask this question on the Numpy board. People there will have more info on how/if you can use an array.

woooee 814 Nearly a Posting Maven

This is the code modified to do 3 at a time in the way that I think you explained.

test_str="1243#74656453634#6356#56456456#565#1212121#7838483#457"
test_str += "#090#720347###24273#18712#478230478#5711758125671#47464"
test_str += "#74647#46474647#19192938#828##25835#2948284#6010203040#"

test_list=test_str.split("#")
##   subtract one from stop because the last letter is a "#"
stop = len(test_list) - 1
for j in range( 0, stop-2 ):
   for k in range( j+1, stop-1 ):
      for m in range( k+1, stop ):
         numbers_list = [ j, k, m ]
         ctr=0
         final_str=""
         while ctr < stop:
            final_str += test_list[ctr]
            if ctr in numbers_list:     ## or ==j, or ==k, or == m if you want
               final_str += "@"
            else:
               final_str += "#"        ## or "!" if you want
            ctr += 1
         print final_str
         print j, k, m, "Hello World\n"
woooee 814 Nearly a Posting Maven

You can split on the "#" and do a single replace for both characters if that helps That's a single pass through the number string for the split() and a single join to put it back together instead of multiple lookup passes to find and replace each number. Instead of the "while()", a "for each_number in test_list", keeping the ctr as well, might be slightly faster over a very large data set since you will not have to find a specific member of the list i.e. each_number is used instead of test_list[ctr].

test_str="1243#74656453634#6356#56456456#565#1212121#7838483#457"
test_str += "#090#720347###24273#18712#478230478#5711758125671#47464"
test_str += "#74647#46474647#19192938#828##25835#2948284#6010203040#"

numbers_list=[ 1, 3, 6, 9, 10]
test_list=test_str.split("#")
stop = len(test_list)
ctr=0
final_str=""
while ctr < stop:
   final_str += test_list[ctr]
   if ctr in numbers_list:
      final_str += "@"
   else:
      final_str += "!"
   ctr += 1
print final_str
woooee 814 Nearly a Posting Maven

This is the problem area

for rec in list_in:
      substrs=rec.split()  
      test_float=abs(float(substrs[2]))
#
#There are probably some blank lines in the file so you have to test each line for length/data
#
for rec in list_in:
      substrs=rec.split()  
      if len(substrs) > 2:
         test_float=abs(float(substrs[2]))
         ## rest of code here
woooee 814 Nearly a Posting Maven

If the above code does not come close to what you want, then you will have to explain it with even more detail for us who are (fill in your own adjective here) folk.

woooee 814 Nearly a Posting Maven

If I understand correctly, this should come close. I break in down into data for each day, and then into the specific range for however many times that range occurs in a day

#!/usr/bin/python

input_file = [
'2008_06_01 08:25 30.1 88.2',
'2008_06_01 08:30 30.9 89.1',
'2008_06_01 08:35 31.8 90.0',
'2008_06_01 08:40 32.7 90.9',
'2008_06_01 08:45 33.6 91.8',
'2008_06_01 08:50 34.4 92.7',
'2008_06_01 08:55 35.3 93.6',
'2008_06_01 09:00 36.2 94.6',
'2008_06_01 09:05 37.0 95.5',
'2008_06_01 09:10 37.9 96.5',
'2008_06_01 09:15 38.8 97.5',
'2008_06_01 09:20 39.6 98.4',
'2008_06_01 09:25 40.5 99.5',
'2008_06_01 09:30 41.4 100.5',
'2008_06_01 09:35 42.2 101.5',
'2008_06_01 09:40 43.1 102.6',
'2008_06_01 09:45 43.9 103.7',
'2008_06_01 09:50 44.8 104.8',
'2008_06_01 10:00 46.0 105.0',
'2008_06_01 16:15 44.4 255.8',
'2008_06_01 16:20 43.6 256.9',
'2008_06_01 16:25 42.7 257.9',
'2008_06_01 16:30 41.9 259.0',
'2008_06_01 16:35 41.0 260.0',
'2008_06_01 16:40 40.1 261.0',
'2008_06_01 16:45 39.3 262.0',
'2008_06_01 16:50 38.4 263.0',
'2008_06_01 16:55 37.6 264.0',
'2008_06_01 17:00 36.7 264.9',
'2008_06_01 17:05 35.8 265.9',
'2008_06_01 17:10 34.9 266.8',
'2008_06_01 17:15 34.1 267.8',
'2008_06_01 17:20 33.2 268.7',
'2008_06_01 17:25 32.3 269.6',
'2008_06_01 17:30 31.5 270.5',
'2008_06_01 17:35 30.6 271.3',
'2008_06_02 08:25 30.1 88.1',
'2008_06_02 08:30 31.0 88.9',
'2008_06_02 08:35 31.9 89.8',
'2008_06_02 08:40 32.7 90.7',
'2008_06_02 08:45 33.6 91.6',
'2008_06_02 08:50 34.5 92.6',
'2008_06_02 08:55 35.4 93.5',
'2008_06_02 09:00 36.2 94.4',
'2008_06_02 09:05 37.1 95.4',
'2008_06_02 09:10 38.0 96.3',
'2008_06_02 09:15 38.8 97.3',
'2008_06_02 09:20 39.7 98.3',
'2008_06_02 09:25 40.6 99.3',
'2008_06_02 09:30 41.4 100.3',
'2008_06_02 09:35 42.3 101.4',
'2008_06_02 09:40 43.1 102.4',
'2008_06_02 09:45 44.0 103.5', …
woooee 814 Nearly a Posting Maven

Print tl, tu, & tm. That should give you some ideas. You might want to use datetime instead or convert everything to seconds..

import datetime
today=datetime.datetime.now()
midnight = datetime.datetime(2008, 2, 25, 0, 0, 0)
if today > midnight:
   print "today is greater", today, "-->", midnight
else:
   print "midnight is greater"
print "difference =", today - midnight
woooee 814 Nearly a Posting Maven

Using a for loop might be easier to understand.

test_list=[1,3,5,7]
ctr = 0
stop=len(test_list)
for j in range(0, stop):
      ctr += 1
      before_add = test_list[j]
      test_list[j] += ctr     ## ctr = j+1 in this specific case
      print "element", j, "did =", before_add, "and now =", test_list[j]
print "\n", test_list
woooee 814 Nearly a Posting Maven

Do you mean the earliest and latest times for one day in the file. That should be fairly straight forward.
min_time=99:99
max_time=00:00
if time < min_time: min_time=time (you will actually have to convert to minutes)
elif time > max_time: max_time=time
Of course you will have to test for date != previous date, but that's the general idea. If you are instead asking about the third column, the same principle is used to find the minimum and maximum with possibly an if value <=45 or value >= 30 thrown in.

woooee 814 Nearly a Posting Maven

Try a
print str(unicode_string_var)
This is assuming that all characters in the variable can be displayed for your locale.

woooee 814 Nearly a Posting Maven

You can use a class to do that in the following way. You could also use a list or dictionary as a container for the 10 variables and pass one list/dictionary instead of 10 variables. IMHO using the class method is preferred.

class test_class:
   def __init__(self):
      self.a="dog"
      self.b="cat"
      self.c=1
      print "__init__, a, b, c =", self.a, self.b, self.c
      self.first_func()
      self.second_func("abc")
   def first_func(self):
      self.c += 1
      print "first_func, a, b, c =", self.a, self.b, self.c
   def second_func(self, d):
      self.c += 1
      print "second_func a, b, c =", self.a, self.b, self.c
      print "d =", d

if __name__ == "__main__":
   TC=test_class()
   print "\n  now calling the functions from outside the class"
   TC.first_func()
   TC.second_func("xyz")
woooee 814 Nearly a Posting Maven

As stated previously, it is difficult to tell without code tags (use the "#" in the icon list). One problem is the two lines below: one is the function definition and the other is the calling line of that function. It is unlikely that this is the problem however. It also looks like the while loop can be an infinite loop if a1 % a2 ==0, since those values are not changed, unless the return statement exits the loop. If that is the case, then when a1 % a2 != 0 there is no value returned=None.
def zufallsZahl(a1,a2):
s1 = zufallsZahl.zufallsZahl()

It should be
def zufallsZahl(a1,a2):
s1 = zufallsZahl.zufallsZahl(b,c)

or (probably this)
def zufallsZahl():
s1 = zufallsZahl.zufallsZahl()

HTH. If not post back using code tags.

woooee 814 Nearly a Posting Maven

You want to use .set() but it must be with a Tkinter control variable. Look for the paragraph that starts with "For example, you could link an Entry widget to a Label widget" and the "Entry" paragraph at this link. The New Mexico Tech Tkinter pages are well done.
http://infohost.nmt.edu/tcc/help/pubs/tkinter/control-variables.html

woooee 814 Nearly a Posting Maven

os.system should work if you just want to run a command. If that doesn't work then subprocess is the next step up.
os.system("perl test.pl -testconfig <config file> > test.log 2>&1")

woooee 814 Nearly a Posting Maven

os.path.walk has a callback function. Note this is untested code. Now that you know what to look for it should be fairly easy to find examples.

import os
def processDirectory ( args, dirname, filenames ):
   print 'Directory',dirname
   for filename in filenames:
      print '     File',filename 
#                                      
top_level_dir = "/usr/local"
os.path.walk(top_level_dir, processDirectory, None )
woooee 814 Nearly a Posting Maven

You'll have to post the significant part of the code as well as the error message. Please use "CODE /CODE" tags ("#" in the top box). First check that you are always using intergers.

woooee 814 Nearly a Posting Maven

ctn_no has to be an integer instead of a string-note that all of the dictionary indexes are now integers and not strings so that you have to use an integer to find something in the dictionary. Also, if ctn_no can not be converted to an integer, you will get an error.
dctSequence[int(ctn_no)+1] = seq_no
or ctn_no = int(temp[16])

woooee 814 Nearly a Posting Maven

I just noticed this. After the final line of this snippet, i will always be zero if it was greater than zero, and -(2i) if it was less than zero. Is that what you are trying to do?

for i in range(0, d):
       if (i % 7 == 0)or (i == 0):
                i -= i
woooee 814 Nearly a Posting Maven

For those of us who were around before there were canned date/time libraries, Zeller's Congruence was common knowledge http://en.wikipedia.org/wiki/Zeller's_congruence but it would have to be modified by comparing the actual day of the week of 01-01-1900 and what you would have to add or subtract to get 01-01-1900 to be a Monday.

woooee 814 Nearly a Posting Maven

Have you tested the code below to see if it does what you think. I don't know myself but it is unclear at best and if you have to explain it, will you be able. The following untested code breaks it down into steps

def leap_year(self, year):
   if (year % 4 == 0) and not(year % 100 == 0)or (year % 400 == 0):
#   
##------- Breaking it down into steps  ---------------------------
   # eliminate this first
   if year % 400 == 0:     ## is leap year
      return 1
   ##   has to be divisible by 4
   if year % 4 == 0:
      # if divisible by 4 and 100 then it is not a leap year
      if (year % 100 == 0):
         return 0
      else:
         return 1
   return 0     ## not a leap year-->not divisible by 4 or 400

As for the days of the week, is the variable d the number of days from 1900? And is the first day in d --> weekday=0, and d==2 --> weekday=1, so then d==8 --> weekday=0 = start over again? If so you should be able to use divmod(d-1, 7) with the remainder being the day of the week.

woooee 814 Nearly a Posting Maven

Try BitBuffer first http://pypi.python.org/pypi/BitBuffer/0.1 You can also use array http://docs.python.org/lib/module-array.html

## "H"=unsigned short int, see the docs
a1 = array.array('H')
fp = open(filename, 'rb')
a1.fromfile(fp, 1)
print a1
a1.fromfile(fp, 1)
print a1
woooee 814 Nearly a Posting Maven

Don't give up, find another way to do it. Worst case is that you post the code for the function readLib(lib), and the contents of lib, or part of the contents if it is large, and ask in specific words "how you can code it to do what you want it to do".

woooee 814 Nearly a Posting Maven

Is it defined as a CollapsiblePane, see here http://www.wxpython.org/docs/api/frames.html You can also check with the wxpython mailing list if you don't find an answer here http://www.wxpython.org/maillist.php

woooee 814 Nearly a Posting Maven

The PC Python installation comes with Tkinter, i.e. TCL/TK, but as Duoas said, you will have to write a simple Python+Tkinter (import Tkinter) program and try it on the IPod. It's limited resources would not have a full blown Python installation, so who knows about Tkinter. It's doubtful that IPod has it. Maybe you can install it, but you may have to work with their native toolkit. Sorry, no one here knows much about it.

woooee 814 Nearly a Posting Maven

GUI's are specific to the OS. What GUIs are available for the IPod and how are you packaging your programs. I don't know what's available for IPods but if there is something like py2exe, you may be able to enbed the graphics in the executable. Also, TCL/Tk/Tkinter, GTK et all may or may not run on the IPod's OS. First you have to find out what's available and then if it can somehow be included with the program. Does IPod have a programming forum where these questions have already been answered. Also you should find out if IPods have a mini python interpreter already or if programs have to be compiled into some form of native code.

woooee 814 Nearly a Posting Maven

You will have to find someone who has used all flavors of Linux to get an answer to that. Since that is impossible, you might have to use a bash script to check for a Python installation, and if Python is installed, if would then run the Python program.

woooee 814 Nearly a Posting Maven

i get to down as far as the tax equation and it won't run,

And you'll have to be more specific. "Won't run" does not say enough and where in hell is the tax equation. Include the error message at the very least (which I am sure is a syntax error, so the question should be, "why do I get this syntax error on this line number in the program").

woooee 814 Nearly a Posting Maven

There are no doubt other and probably better ways to do this, but try
print url.split("/")
You want the 3rd item, or result[2]. You can then add it to a list or dictionary if it is not already in the list or dictionary.

woooee 814 Nearly a Posting Maven

Key "python" into a terminal. If you get the python prompt (>>>) then you have Python installed. Ctrl-D exits python. Most distros will have it installed in /usr/bin, so you can also check for a /usr/bin/python2.x file.

woooee 814 Nearly a Posting Maven

You can also read all of the file into memory, process it once to search for the string, and then process it a second time to write it to a file if necessary.

data = open(filename, "r").readlines()
found = 0
for rec in data:
   if ("sa001:" in rec) or ("SA001:") in rec:
      print "SA001 found"
      found =1
      
## file only changes if string is not found
if not found:
   fp = open(filename+".2", "w")
   fp.write( "SA001:\n")          ## add this line
   for rec in data:                       ## original data
      fp.write(rec)
   fp.close()
woooee 814 Nearly a Posting Maven

Here is an article about users input that covers all of the bases http://linuxgazette.net/issue83/evans.html

woooee 814 Nearly a Posting Maven

Did you find a solution to this? If not, ask on the Ubuntu forum http://ubuntuforums.org/forumdisplay.php?f=39 You probably have to install one of the libcairo or libcairo dev packages.

woooee 814 Nearly a Posting Maven

http://docs.python.org/lib/module-os.path.html
You can also use os.path.exists() but that will return True if you just supply just a directory name and you want to test directory + file name.

On to the bounds checking. When someone chooses what type of ship they want to build, a bomber etc., what happens if they enter a number that is not on the list? Also, you could combine ships, ships_cost and ships_shipyard into one container, probably a dictionary of lists, but that is not all that big of a deal when starting out.

woooee 814 Nearly a Posting Maven

It works fine for me. I could only get it to crash by selecting "Use Saved Data"=1 (yes) on the first pass. Of course there is no saved data the first time you run the program, so you want to use os.path.isfile() in the load_saved function to check for a file before you try to open it.

woooee 814 Nearly a Posting Maven

Let's forget about bounds checking for now. I'm talking about a different section of the program. What does "crashes" mean. What is the error message and does it actually save the data (look at the length and time stamp for the file).

Edit: I think this is the problem

def save_data(file_name,data):
   import pickle        ## should be at the beginning of the program so it imports once 
   data_file = open(file_name, 'wb')
   pickle.dump(data,data_file)
   file.close()                    ## should be data_file.close()
AJG commented: Helpful. +1
woooee 814 Nearly a Posting Maven

def save_data(file_name,data):

if saved == 2:
bases = input("Type your number of bases:")
save_data('bases.txt',bases) ## bases is just a number and not data isn't it?
# PROGRAM CRASHES HERE

What happens when someone keys in an "a" instead of a number, or 155 instead of 15?

woooee 814 Nearly a Posting Maven

When the users makes a choice, i.e.
choice = input("What do you wish to produce?")-1
you should test for bounds. (choice < 1) or (choice > max) would yield an error and ask the user to choose again.

woooee 814 Nearly a Posting Maven

KDE and Gnome both have startup options in the menu. If you are using some other desktop manager then you may have to add it to /etc/init.d depending on which Linux distro you are using.

woooee 814 Nearly a Posting Maven

Firstly, I can't get the '\n' from the line before putting it in a list.

I don't think "firstly" is a word, but I'm not sure.
var=var.strip()
will remove all whitespace before and after the text for the variable var. Whitespace is spaces, tabs, newlines, etc. As for the "too many values to unpack", it probably refers to this line
for key,value in lib[0::2], lib[1::2]:
but it is impossible to tell without the entire error message. It doesn't matter though since you will have to print some things to find out anyway. Start by putting these before the aforementioned for statement
print "lib[0] =", lib[0]
print "lib[1] =", lib[1]
print "lib[0::2], lib[1::2] =", lib[0::2], lib[1::2]
Hopefully that will give you some hints about what comes after the "in" in the for statement.

woooee 814 Nearly a Posting Maven

The swipper may send an identifying string at the beginning of the transmission. Take a look a the first few bytes. You will probably have to use ord() since the best way to distinguish it as something other than the keyboard is to use decimal values that the keyboard would not transmit.

woooee 814 Nearly a Posting Maven

I almost never read a thread that starts with "Please help me". It is too vague to even bother with. This was one of the results of a google for "python ascii" . You can also use the ord() function (google for it) on each character to see if the decimal value is within the ASCII range. You will also have to google for ASCII decimal ranges if you don't know what they are. Also, please add "Solved" to the topic if this answers your question, so others won't waste their time reading a thread that has already been solved.
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/163743

woooee 814 Nearly a Posting Maven

How is the swipper connected to the computer. If it is through a serial port, then you can use pyserial and detect when there is data in the serial port to be read. Without more info there is no way to help.

woooee 814 Nearly a Posting Maven

Or put them both in the same dictionary. There is only 100 or so-times 2

# small dictionary of chemical symbols
symbol_dic = {
'C': 'carbon',
'H': 'hydrogen',
'N': 'nitrogen',
'Li': 'lithium',
'Be': 'beryllium',
'B': 'boron'
}

keys_list=symbol_dic.keys()
for key in keys_list:
   symbol_dic[symbol_dic[key]]=key
Ene Uran commented: very nice idea +4
woooee 814 Nearly a Posting Maven

NoneType usually means you are trying to use a variable that has not been defined. Without code and the error message it is impossible to tell anything at all.

woooee 814 Nearly a Posting Maven

I am assuming that every other record is a county followed by population housing location. This is how to use a readline() loop, (and is untested code):

def process_county(r_list):
   print "County =", r_list[0]
   print "Housing Loc =", r_list[1]

fp=open(filename, "r")
r_list=[]
rec=fp.readline()     ##county rec
while rec:
   r_list.append(rec)
   rec=fp.readline()     ## housing rec
   r_list.append(rec)
   process_county(r_list)
   r_list=[]
   rec=fp.readline()     ## county rec
fp.close()