PythonCard and Py2Exe
I've been banging my head against this problem for a week. It's time to ask for help, because I'm obviously not going to solve this by trial and error. I'm trying to create a standalone version (.exe) of PythonCard's Custdb sample using Py2Exe version 0.5.0. Everytime I attempt to compile the program, I get an error during compilation. I need to formulate the correct setup file. Here's the one I began with: from distutils.core import setup from PythonCard import dialog, model import PythonCard import py2exe setup( name = "custdb", console = ["custdb.py"], data_files = [ (".", ["custdb.ini", "custdb.rsrc.py", "customerdata.csv"]) ] ) Every variation of this format failed. Does anyone have any ideas of how to re-write this Setup file? -- http://mail.python.org/mailman/listinfo/python-list
Re: PythonCard and Py2Exe
For this setup file, the executable packs, but when I attempt to run the program, the screen flashes, " cannot import name radiogroup ". I've attempted adding "import radiogroup", "from Pythoncard import radiogroup" and "from Pythoncard.compnents import radiogroup" to the setup file, and that doesn't help. It simply terminates with no error. I've tried removing all references to radiogroup from the script's resource file, but that defeats the purpose, as the list box is central to the script's use. My computer runs the script fine, so the radiogroup module must be there. I must just have the imports written wrong. -- http://mail.python.org/mailman/listinfo/python-list
Re: PythonCard and Py2Exe
> You should move these 'import ...' statements to your *script* so that > py2exe doesn find them, not to the setup script. > > Thomas Removing import statements only returns this error message before the package compiles: = "custdb", 'setup' is not defined No files are returned. -- http://mail.python.org/mailman/listinfo/python-list
Re: PythonCard and Py2Exe
The Error: (Most recent call last): C:\Documents and Settings\Gateway User\ Desktop\custdb\setup.py", line 1, name = "custdb", 'setup' is not defined There may be a single word infront of 'setup' on the fourth line, it scramble on my screen because I have to use a screen capture to read the error (it pops up for just a second before the window shuts down. Here's the full setup.py script I ran to get the error: from distutils.core import setup import py2exe setup( name = "custdb", console = ["custdb.py"], data_files = [ (".", ["custdb.ini", "custdb.de.rsrc.py" "custdb.rsrc.py", "customerdata.csv"]) ] ) *note: "data_files" is all one line in my Python IDLE -- http://mail.python.org/mailman/listinfo/python-list
Re: PythonCard and Py2Exe
I am using the command prompt. What I realized after reading your entry, Peter, is that if I use "setup.py py2exe" instead of "start setup.py py2exe" I can see the error in the same window without it closing. I went into the script and double spaced everything in case Notebook smashed the lines together while I was tweaking the code. After that, the code resumed packing. Now, however, it seems I'm back where I started. Running the .Exe returned this error: Traceback (most recent call last): File "custdb.py", line 202, in ? app = model.Application(CustDbStack) File "PythonCard\model.pyc", line 337, in __init__ File "PythonCard\resource.pyc", line 48, in getResource File "PythonCard\resource.pyc", line 86, in __init__ File "PythonCard\resource.pyc", line 91, in __init__ File "PythonCard\resource.pyc", line 91, in __init__ File "PythonCard\resource.pyc", line 96, in __init__ File "PythonCard\resource.pyc", line 139, in enforceSpec File "PythonCard\resource.pyc", line 30, in loadComponentModule ImportError: cannot import module 'radiogroup Cannot import module 'radiogroup' was the initial problem I was having. This is just a more detailed error message. -- http://mail.python.org/mailman/listinfo/python-list
PythonCard and Py2Exe
I'm trying to create a standalone version (.exe) of PythonCard's Custdb sample using Py2Exe version 0.5.0. Everytime I attempt to compile the program, I get an error during compilation. This is the exact code I'm using in the setup file: from distutils.core import setup import py2exe setup( name = "custdb", console = ["custdb.py"], data_files = [ (".", ["custdb.ini", "custdb.de.rsrc.py", "custdb.rsrc.py", "customerdata.csv"]) ] ) This is the error message I get when I run custdb.exe: Traceback (most recent call last): File "custdb.py", line 202, in ? app = model.Application(CustDbStack) File "PythonCard\model.pyc", line 337, in __init__ File "PythonCard\resource.pyc", line 48, in getResource File "PythonCard\resource.pyc", line 86, in __init__ File "PythonCard\resource.pyc", line 91, in __init__ File "PythonCard\resource.pyc", line 91, in __init__ File "PythonCard\resource.pyc", line 96, in __init__ File "PythonCard\resource.pyc", line 139, in enforceSpec File "PythonCard\resource.pyc", line 30, in loadComponentModule ImportError: cannot import module 'radiogroup When I add "radiogroup" to the imports at the top of custdb.py, I get this error message: Traceback (most recent call last): File "custdb.py", line 18, in ? ImportError: cannot import name radiogroup This is line 18 in Custdb.py: from PythonCard import dialog, model, radiogroup -- http://mail.python.org/mailman/listinfo/python-list
PythonCard and Py2Exe
I'm trying to create a standalone version (.exe) of PythonCard's Custdb sample using Py2Exe version 0.5.0. Everytime I attempt to compile the program, I get an error during compilation. This is the exact code I'm using in the setup file: from distutils.core import setup import py2exe setup( name = "custdb", console = ["custdb.py"], data_files = [ (".", ["custdb.ini", "custdb.de.rsrc.py", "custdb.rsrc.py", "customerdata.csv"]) ] ) This is the error message I get when I run custdb.exe: Traceback (most recent call last): File "custdb.py", line 202, in ? app = model.Application(CustDbStack) File "PythonCard\model.pyc", line 337, in __init__ File "PythonCard\resource.pyc", line 48, in getResource File "PythonCard\resource.pyc", line 86, in __init__ File "PythonCard\resource.pyc", line 91, in __init__ File "PythonCard\resource.pyc", line 91, in __init__ File "PythonCard\resource.pyc", line 96, in __init__ File "PythonCard\resource.pyc", line 139, in enforceSpec File "PythonCard\resource.pyc", line 30, in loadComponentModule ImportError: cannot import module 'radiogroup When I add "radiogroup" to the imports at the top of custdb.py, I get this error message: Traceback (most recent call last): File "custdb.py", line 18, in ? ImportError: cannot import name radiogroup This is line 18 in Custdb.py: from PythonCard import dialog, model, radiogroup -- http://mail.python.org/mailman/listinfo/python-list
PythonCard and Py2Exe
I'm trying to create a standalone version (.exe) of PythonCard's Custdb sample using Py2Exe version 0.5.0. Everytime I attempt to compile the program, I get an error during compilation. This is the exact code I'm using in the setup file: from distutils.core import setup import py2exe setup( name = "custdb", console = ["custdb.py"], data_files = [ (".", ["custdb.ini", "custdb.de.rsrc.py", "custdb.rsrc.py", "customerdata.csv"]) ] ) This is the error message I get when I run custdb.exe: Traceback (most recent call last): File "custdb.py", line 202, in ? app = model.Application(CustDbStack) File "PythonCard\model.pyc", line 337, in __init__ File "PythonCard\resource.pyc", line 48, in getResource File "PythonCard\resource.pyc", line 86, in __init__ File "PythonCard\resource.pyc", line 91, in __init__ File "PythonCard\resource.pyc", line 91, in __init__ File "PythonCard\resource.pyc", line 96, in __init__ File "PythonCard\resource.pyc", line 139, in enforceSpec File "PythonCard\resource.pyc", line 30, in loadComponentModule ImportError: cannot import module 'radiogroup When I add "radiogroup" to the imports at the top of custdb.py, I get this error message: Traceback (most recent call last): File "custdb.py", line 18, in ? ImportError: cannot import name radiogroup This is line 18 in Custdb.py: from PythonCard import dialog, model, radiogroup -- http://mail.python.org/mailman/listinfo/python-list
Py2Exe Import Error
I'm trying to create a standalone version (.exe) of PythonCard's Custdb sample using Py2Exe version 0.5.0. Everytime I attempt to compile the program, I get an error during compilation. This is the exact code I'm using in the setup file: from distutils.core import setup import py2exe setup( name = "custdb", console = ["custdb.py"], data_files = [ (".", ["custdb.ini", "custdb.de.rsrc.py", "custdb.rsrc.py", "customerdata.csv"]) ] ) This is the error message I get when I run custdb.exe: Traceback (most recent call last): File "custdb.py", line 202, in ? app = model.Application(CustDbStack) File "PythonCard\model.pyc", line 337, in __init__ File "PythonCard\resource.pyc", line 48, in getResource File "PythonCard\resource.pyc", line 86, in __init__ File "PythonCard\resource.pyc", line 91, in __init__ File "PythonCard\resource.pyc", line 91, in __init__ File "PythonCard\resource.pyc", line 96, in __init__ File "PythonCard\resource.pyc", line 139, in enforceSpec File "PythonCard\resource.pyc", line 30, in loadComponentModule ImportError: cannot import module 'radiogroup When I add "radiogroup" to the imports at the top of custdb.py, I get this error message: Traceback (most recent call last): File "custdb.py", line 18, in ? ImportError: cannot import name radiogroup This is line 18 in Custdb.py: from PythonCard import dialog, model, radiogroup -- http://mail.python.org/mailman/listinfo/python-list
Re: PythonCard and Py2Exe
That did it. Thanks a lot. -- http://mail.python.org/mailman/listinfo/python-list
Changing a value for each folder while traversing a file system
I'm using the script below (originally from http://effbot.org, given to me here) to open all of the text files in a directory and its subdirectories and combine them into one Rich text file (index.rtf). Now I'm adapting the script to convert all the text files into individual html files. What I can't figure out is how to trigger a change in the background value for each folder change (not each file), so that text is color-coded by folder. I have tried to integrate the following snippet into the directory walker, so that I could later write it to the file as text: color = random.choice(["#99", "#CC", "#99"]) That method didn't work, does anyone else have a suggestion? #! /usr/bin/python import glob import fileinput import os import string import sys index = open("index.rtf", 'w') class DirectoryWalker: # a forward iterator that traverses a directory tree, and # returns the filename def __init__(self, directory): self.stack = [directory] self.files = [] self.index = 0 def __getitem__(self, index): while 1: try: file = self.files[self.index] self.index = self.index + 1 except IndexError: # pop next directory from stack self.directory = self.stack.pop() self.files = os.listdir(self.directory) self.index = 0 else: # get a filename, eliminate directories from list fullname = os.path.join(self.directory, file) if os.path.isdir(fullname) and not os.path.islink(fullname): self.stack.append(fullname) else: return fullname for file in DirectoryWalker("."): # divide files names into path and extention path, ext = os.path.splitext(file) # choose the extention you would like to see in the list if ext == ".txt": print file file = open(file) fileContent = file.readlines() # just for example, let's say I want to print the color here as if in an html tag... index.write(color) for line in fileContent: if not line.startswith("\n"): index.write(line) index.write("\n") index.close() -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing a value for each folder while traversing a file system
No, that doesn't work. Though, leaving the random snippet about the "for file in DirectoryWalker("."):" line, it does leave all files the same value, rather than switching the value for every single file. The problem is, the value is shared accross every folder. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing a value for each folder while traversing a file system
That seems logical, but the syntax doesn't work. I keep getting the error: 'module object' has no attribute 'dirname' -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing a value for each folder while traversing a file system
Perfect. That's exactly what I wanted. Thanks. For those reading this later on, the following script will crawl through a directory, select all the text files, dump them into seperate numbered html files in the parent directory (in which the python script is executed). In this example, the first line of the text file is placed into a table with a randomly colored background. With a little work, the text files can be complexly formatted, each folder can be color coded, etc. #! /usr/bin/python import glob import fileinput import os import string import sys count == 1 number == 1 class DirectoryWalker: # a forward iterator that traverses a directory tree, and # returns the filename def __init__(self, directory): self.stack = [directory] self.files = [] self.index = 0 def __getitem__(self, index): while 1: try: file = self.files[self.index] self.index = self.index + 1 except IndexError: # pop next directory from stack self.directory = self.stack.pop() self.files = os.listdir(self.directory) self.index = 0 else: # get a filename, eliminate directories from list fullname = os.path.join(self.directory, file) if os.path.isdir(fullname) and not os.path.islink(fullname): self.stack.append(fullname) else: return fullname for file in DirectoryWalker("."): last_directory = None for file in DirectoryWalker("."): issue = number +".html" directory = os.path.dirname(file) if directory != last_directory: color = random.choice(["#99", "#009900", "#99"]) last_directory = directory # divide files names into path and extention path, ext = os.path.splitext(file) # choose the extention you would like to see in the list if ext == ".txt": print file file = open(file) fileContent = file.readlines() # just for example, let's say I want to print the color here as if in an html tag... issue.write("") for line in fileContent: if not line.startswith("\n"): if count == 1: issue.write('') issue.write(line) issue.write("") count = count + 1 else: issue.write("") issue.write(line) issue.write("") issue.write("") issue.close() -- http://mail.python.org/mailman/listinfo/python-list
Expanding Search to Subfolders
This is the beginning of a script that I wrote to open all the text files in a single directory, then process the data in the text files line by line into a single index file. os.chdir("C:\\Python23\\programs\\filetree") mydir = glob.glob("*.txt") index = open("index.rtf", 'w') for File in mydir: count = 1 file = open(File) fileContent = file.readlines() for line in fileContent: if not line.startswith("\n"): if count == 1: I'm now trying to the program to process all the text files in subdirectories, so that I don't have to run the script more than once. I know that the following script will SHOW me the contents of the subdirectories, but I can't integrate the two: def print_tree(tree_root_dir): def printall(junk, dirpath, namelist): for name in namelist: print os.path.join(dirpath, name) os.path.walk(tree_root_dir, printall, None) print_tree("C:\\Python23\\programs\\filetree") I've taught myself out of online tutorials, so I think that this is a matter of a command that I haven't learned rather a matter of logic. Could someone tell me where to learn more about directory processes or show me an improved version of my first script snippet? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Expanding Search to Subfolders
Thanks, that was a big help. It worked fine once I removed > os.chdir("C:\\Python23\\programs\\Magazine\\SamplesE") and changed "for file, st in DirectoryWalker("."):" to "for file in DirectoryWalker("."):" (removing the "st") -- http://mail.python.org/mailman/listinfo/python-list
Re: Expanding Search to Subfolders
Thanks everyone! -- http://mail.python.org/mailman/listinfo/python-list
Re: Expanding Search to Subfolders
Here's the final working script. It opens all of the text files in a directory and its subdirectories and combines them into one Rich text file (index.rtf): #! /usr/bin/python import glob import fileinput import os import string import sys index = open("index.rtf", 'w') class DirectoryWalker: # a forward iterator that traverses a directory tree, and # returns the filename def __init__(self, directory): self.stack = [directory] self.files = [] self.index = 0 def __getitem__(self, index): while 1: try: file = self.files[self.index] self.index = self.index + 1 except IndexError: # pop next directory from stack self.directory = self.stack.pop() self.files = os.listdir(self.directory) self.index = 0 else: # get a filename, eliminate directories from list fullname = os.path.join(self.directory, file) if os.path.isdir(fullname) and not os.path.islink(fullname): self.stack.append(fullname) else: return fullname for file in DirectoryWalker("."): # divide files names into path and extention path, ext = os.path.splitext(file) # choose the extention you would like to see in the list if ext == ".txt": print file # print the contents of each file into the index file = open(file) fileContent = file.readlines() for line in fileContent: if not line.startswith("\n"): index.write(line) index.write("\n") index.close() -- http://mail.python.org/mailman/listinfo/python-list