RE: tkFileDialogs

2012-07-06 Thread brandon harris
It doesn't matter whether I pass the actual path in or the global variable 
name.  The result is the same. 

Brandon L. Harris


From: Karim [kliat...@gmail.com]
Sent: Friday, July 06, 2012 12:42 AM
To: brandon harris
Subject: Re: tkFileDialogs

Le 06/07/2012 07:22, brandon harris a écrit :
 I'm wanting to allow users to select hidden directories in windows and it 
 seems that using the tkFileDialog.askdirectory() won't allow for that.  It's 
 using the tkFileDialog.Directory class which calls an internal command 
 'tk_chooseDirectory' .  However the file selector dialogs (askopenfilename, 
 asksaveasfilename, etc) has the common windows dialog which supports showing 
 hidden folders.  It's using the tkFileDialog.Open class which is calling an 
 internal command of 'tk_getOpenFile'.

 Can anyone shed light on why these two dialogs are so very different and 
 possibly give me a solution to this hidden directory issue.  I have found 
 that you can't really use the Open class because it's going to require a file 
 be selected, not a directory and the Directory class won't navigate to or 
 have an initialdir that is hidden (on windows the %APPDAT% folder is hidden 
 by default)

 Windows Example Code.

 import tkFileDialog
 # Won't start in or allow navigation to APPDATA
 test = tkFileDialog.askdirectory(initialdir='%APPDATA%')
 # Will start in and navigate to APPDATA
 test = tkFileDialog.askopenfile(initialdir='%APPDATA%')

 Thanks in advance for any help given!


 Brandon L. Harris
Heuu.

Don't you use os.environ['APPDATA'] if this is an environment variable?

Cheers
karim
-- 
http://mail.python.org/mailman/listinfo/python-list


tkFileDialogs

2012-07-05 Thread brandon harris
I'm wanting to allow users to select hidden directories in windows and it seems 
that using the tkFileDialog.askdirectory() won't allow for that.  It's using 
the tkFileDialog.Directory class which calls an internal command 
'tk_chooseDirectory' .  However the file selector dialogs (askopenfilename, 
asksaveasfilename, etc) has the common windows dialog which supports showing 
hidden folders.  It's using the tkFileDialog.Open class which is calling an 
internal command of 'tk_getOpenFile'.

Can anyone shed light on why these two dialogs are so very different and 
possibly give me a solution to this hidden directory issue.  I have found that 
you can't really use the Open class because it's going to require a file be 
selected, not a directory and the Directory class won't navigate to or have an 
initialdir that is hidden (on windows the %APPDAT% folder is hidden by default)

Windows Example Code.

import tkFileDialog
# Won't start in or allow navigation to APPDATA
test = tkFileDialog.askdirectory(initialdir='%APPDATA%')
# Will start in and navigate to APPDATA
test = tkFileDialog.askopenfile(initialdir='%APPDATA%')

Thanks in advance for any help given!


Brandon L. Harris
-- 
http://mail.python.org/mailman/listinfo/python-list


Python Pickling Issue

2011-11-03 Thread Brandon Harris
I have written a fairly large DAG with python and I've run into an issue 
when attempting to pickle the data to disk.
It will pickle fine the first time, but if I call pickle again, it 
throws this error.


/usr/lib64/python2.6/copy_reg.py in _reduce_ex(self, proto)
 68 else:
 69 if base is self.__class__:
--- 70 raise TypeError, can't pickle %s objects % 
base.__name__

 71 state = base(self)
 72 args = (self.__class__, base, state)

TypeError: can't pickle function objects

I'm calling
save_file = open('my_file.rsf', 'w')
cPickle.dump(self, save_file)

I have attempted to pickle the object to a different file after the 
first time, but the error is still thrown.


This wouldn't be very hard to track down if the error gave any 
indication as to where or what this function it can't pickle is, so
if there's any possible way to at least get the name of what's failing 
to be pickled, that would be a win.


Thanks in advance for all replies.

Brandon L. Harris

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Pickling Issue

2011-11-03 Thread Brandon Harris
After digging around a while I discovered I was attempting to pickle a 
third party class that can't be pickled. Initially I was removing it 
before pickling and everything was kosher, but at some point it got back 
onto the class. Apologies.


Brandon L. Harris


On 11/03/2011 09:42 AM, Brandon Harris wrote:
I have written a fairly large DAG with python and I've run into an 
issue when attempting to pickle the data to disk.
It will pickle fine the first time, but if I call pickle again, it 
throws this error.


/usr/lib64/python2.6/copy_reg.py in _reduce_ex(self, proto)
 68 else:
 69 if base is self.__class__:
--- 70 raise TypeError, can't pickle %s objects % 
base.__name__

 71 state = base(self)
 72 args = (self.__class__, base, state)

TypeError: can't pickle function objects

I'm calling
save_file = open('my_file.rsf', 'w')
cPickle.dump(self, save_file)

I have attempted to pickle the object to a different file after the 
first time, but the error is still thrown.


This wouldn't be very hard to track down if the error gave any 
indication as to where or what this function it can't pickle is, so
if there's any possible way to at least get the name of what's failing 
to be pickled, that would be a win.


Thanks in advance for all replies.

Brandon L. Harris



--
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 8 and extraneous whitespace

2011-07-22 Thread Brandon Harris
Poor sod? Makes it sound bad when you say it like that. I am not forced 
to work at that fixed width, but when I work with code, I often have my 
vim session split vertically and it's super important to keep things at 
80 character to quickly read/edit code.


Brandon L. Harris

On 07/22/2011 02:13 PM, John Gordon wrote:

In98u00kfnf...@mid.individual.net  Neil Ceruttine...@norwich.edu  writes:


You can fit much more code per unit of horizontal space with a
proportionally spaced font. As a result, that issue, while valid,
is significantly reduced.

Is it?  I assume one major reason for the 80-character limit is to help
the poor sod who will eventually get stuck working with your code on an
80-column fixed width terminal window.



--
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 8 and extraneous whitespace

2011-07-21 Thread Brandon Harris
I don't really think lining things up makes them any easier to read. In 
fact, the consistency in a single space on either side of an operator 
keeps things neat and clean. Also easier to maintain in any editor. 
Always lining up columns of stuff requires readjusting text every time 
you add a new longer variable and you can never be consistent in how 
much whitespace is there.


Brandon L. Harris


On 07/21/2011 01:46 PM, Andrew Berg wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: RIPEMD160

On 2011.07.21 01:32 PM, Thomas Jollans wrote:

So, the PEP says: do not align operators. End of story.

I'm pretty sure that colons, commas and equals signs are not operators.

- -- 
CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0

PGP/GPG Public Key ID: 0xF88E034060A78FCB
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAwAGBQJOKHQGAAoJEPiOA0Bgp4/LouMH/3sufiaJiwrD10eVsUlA4rZ0
XpHnXPOl8WY8C1Qv4OFmg2bN5Qd2S5qEhLgwoUDuZVInx8BAN5IPjIms5YQzgyD5
2PWntkPbxyiV+LfZXwKNPuCW4U4WDMznNThdZz3eUVruBkq6PZMv4yqL7XcZLx5T
KQG+MNkOxGCXk6ZnNgWHGm2eGP01wAmZyvuB16vifVblH6Gk0Uq1FKjReVsszAI5
updUNgpPMskN9c3N8eU+vrHI839G7yPKtujEZ0LCO2552Ogn4vIsWR+Ir0FBLzcB
EBqDzZRmEcCyHobeaLaBZ2qI3OpsF/CTVzx92gqfmf2qhwiSZUFrVqWdmLVhgQc=
=P7QL
-END PGP SIGNATURE-


--
http://mail.python.org/mailman/listinfo/python-list


Python threading/multiprocessing issue.

2011-07-15 Thread Brandon Harris

I'm working on a tool that runs a number of process is separate thread.
I've, up to this point, been using threading.Thread, but from what I
read multiprocess will allow multiple processors to be used
From the python docs on multiprocessing.
Due to this, the multiprocessing module allows the programmer to fully
   leverage multiple processors on a given machine.

I have run into an issue when modifying the thread object from the run
method. Threading.thread allows me to change an attribute in the run 
method and it hold while multiprocessing.Process loses it.


Here is an example illustrating the inconsistency that I've seen.

--
|
import time
import multiprocessing
import threading

def simple_process_call():
my_process = SimpleProcess()
my_process.start()
while not my_process.done.is_set():
pass

print my_process.my_attribute

class SimpleProcess(multiprocessing.Process):
def __init__(self):
super(SimpleProcess, self).__init__()
self.my_attribute = 'Fail'
self.done = multiprocessing.Event()

def run(self):
self.my_attribute = 'Success'
time.sleep(5)
self.done.set()

def simple_thread_call():
my_thread = SimpleThread()
my_thread.start()
while not my_thread.done.is_set():
pass

print my_thread.my_attribute

class SimpleThread(threading.Thread):
def __init__(self):
super(SimpleThread, self).__init__()
self.my_attribute = 'Fail'
self.done = threading.Event()

def run(self):
self.my_attribute = 'Success'
time.sleep(5)
self.done.set()

if __name__ == '__main__':
# simple_process_call()
simple_thread_call()|


--

The odd thing is that I can modify the multiprocessing.Event and it 
holds, but modifying any attribute on the class goes away.


If I am super ignorant of something, please cure me of it.

Thanks in advance!



Brandon L. Harris

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python threading/multiprocessing issue.

2011-07-15 Thread Brandon Harris
I see. Well I was hoping to see the same result in the multiprocessing 
example as using the threading example. What you pointed out makes sense 
though, but what I don't understand is how modifying the queue in the 
example works fine in both. Possibly it was designed for that kind of use?


Brandon L. Harris


On 07/15/2011 03:55 PM, Lee Harr wrote:

I'm working on a tool that runs a number of process is separate thread.
I've, up to this point, been using threading.Thread, but from what I
read multiprocess will allow multiple processors to be used
   From the python docs on multiprocessing.
Due to this, the multiprocessing module allows the programmer to fully
  leverage multiple processors on a given machine.

I have run into an issue when modifying the thread object from the run
method. Threading.thread allows me to change an attribute in the run
method and it hold while multiprocessing.Process loses it.


I am not a multiprocessing expert, but I think the problem you
are having is that Process is running your code in a separate
process, so there is no way you could see those object changes
in your main line code.

In other words, Process is not an exact replacement for Thread.
If you need to communicate between the different parts, you
would want to use the abstractions provided by Queue or Pipe.


Keep reading down the multiprocessing page in the docs until
you get to Exchanging objects between processes:
http://docs.python.org/library/multiprocessing.html#exchanging-objects-between-processes


Sharing state between processes seems like it will be especially
relevant to what you are doing:
http://docs.python.org/library/multiprocessing.html#sharing-state-between-processes

Basically, it says don't do that  :o)



Here is an example illustrating the inconsistency that I've seen.

One thing that would help here is a sample of what output
you get from your code, and what you were hoping to get.




--
http://mail.python.org/mailman/listinfo/python-list


Python threading/multiprocessing issue.

2011-07-14 Thread Brandon Harris

I'm working on a tool that runs a number of process is separate thread.
I've, up to this point, been using threading.Thread, but from what I
read multiprocess will allow multiple processors to be used
From the python docs on multiprocessing.
Due to this, the multiprocessing module allows the programmer to fully
   leverage multiple processors on a given machine.

I have run into an issue when modifying the thread object from the run
method. Threading.thread allows me to change an attribute in the run 
method and it hold while multiprocessing.Process loses it.


Here is an example illustrating the inconsistency that I've seen.

--
|
import time
import multiprocessing
import threading

def simple_process_call():
my_process = SimpleProcess()
my_process.start()
while not my_process.done.is_set():
pass

print my_process.my_attribute

class SimpleProcess(multiprocessing.Process):
def __init__(self):
super(SimpleProcess, self).__init__()
self.my_attribute = 'Fail'
self.done = multiprocessing.Event()

def run(self):
self.my_attribute = 'Success'
time.sleep(5)
self.done.set()

def simple_thread_call():
my_thread = SimpleThread()
my_thread.start()
while not my_thread.done.is_set():
pass

print my_thread.my_attribute

class SimpleThread(threading.Thread):
def __init__(self):
super(SimpleThread, self).__init__()
self.my_attribute = 'Fail'
self.done = threading.Event()

def run(self):
self.my_attribute = 'Success'
time.sleep(5)
self.done.set()

if __name__ == '__main__':
# simple_process_call()
simple_thread_call()|


--

The odd thing is that I can modify the multiprocessing.Event and it 
holds, but modifying any attribute on the class goes away.


If I am super ignorant of something, please cure me of it.

Thanks in advance!



Brandon L. Harris

-- 
http://mail.python.org/mailman/listinfo/python-list


Passing File Objects into Subprocess.Popen

2010-11-04 Thread Brandon Harris
 I'm running python 2.5 and have bumped into an issue whereby the PIPE 
in subprocess.Popen locks up after taking too many characters. I found 
some documentation that discuss this problem and offers some ideas for 
solutions, the best one being to pass a file object into subprocess 
instead of PIPE. This will allow for much larger std output.


http://thraxil.org/users/anders/posts/2008/03/13/Subprocess-Hanging-PIPE-is-your-enemy/

The problem is that, while I can pass in a tempfile.TemporaryFile() and 
everything seems to go swimmingly, there doesn't seem to be anything 
written to file I handed Popen.


import tempfile
import subprocess

def awesome():
# I understand that not everyone has nuke, but it doesn't seem to 
matter what I run through it

# the result is the same.
my_cmd = '/usr/local/Nuke6.0v3/Nuke6.0 -V'

my_stderr = tempfile.TemporaryFile()
my_stdout = tempfile.TemporaryFile()

process = subprocess.Popen(my_cmd, stderr=my_stderr, stdout=my_stdout)
process.wait()

print my_stderr.read()
print my_stdout.read()

print Finished!!!

Any help on this issue would be awesome! thanks!

Brandon L. Harris



--
http://mail.python.org/mailman/listinfo/python-list


Re: Passing File Objects into Subprocess.Popen

2010-11-04 Thread Brandon Harris
 What do you mean by rewind the file pointer before reading from it? 
Seek back to the beginning? And It sounded very unlikely to me too, but 
it's the only thing I have found that explains why a very verbose job 
with tons of feedback locks up at the same point and won't process at all.


I did try running communicate before and after the wait() but to no avail.

Brandon L. Harris


On 11/04/2010 05:39 PM, Antoine Pitrou wrote:

Try to rewind the file pointer before reading from it.


--
http://mail.python.org/mailman/listinfo/python-list


Re: Passing File Objects into Subprocess.Popen

2010-11-04 Thread Brandon Harris
 ok. Jumping back to the start of the file solved the problem. 
(file.seek(0)) Big thanks for that insight!


Brandon L. Harris


On 11/04/2010 05:49 PM, Brandon Harris wrote:
 What do you mean by rewind the file pointer before reading from it? 
Seek back to the beginning? And It sounded very unlikely to me too, 
but it's the only thing I have found that explains why a very verbose 
job with tons of feedback locks up at the same point and won't process 
at all.


I did try running communicate before and after the wait() but to no 
avail.


Brandon L. Harris


On 11/04/2010 05:39 PM, Antoine Pitrou wrote:

Try to rewind the file pointer before reading from it.




--
http://mail.python.org/mailman/listinfo/python-list


eval string

2010-09-30 Thread Brandon Harris
 Needing to pass a string command into a third party program and having 
issues creating a string to do what I need.


here's what I have so far.

eval('import sys; 
sys.stderr.write(\'\n\n\nCompleted!!!\nCompleted!!!\nCompleted!!!\nCompleted!!!\nCompleted!!!\nCompleted!!!\n\n\n\');')


Traceback (most recent call last):
  File stdin, line 1, in module
  File string, line 1
sys.stderr.write('
 ^
SyntaxError: EOL while scanning string literal


so I've changed it up every way I can think and I get other errors.

eval('import sys; 
sys.stderr.write(\n\n\nCompleted!!!\nCompleted!!!\nCompleted!!!\nCompleted!!!\nCompleted!!!\nCompleted!!!\n\n\n);')


Traceback (most recent call last):
  File stdin, line 1, in module
  File string, line 1
import sys; sys.stderr.write(
 ^
SyntaxError: invalid syntax


Brandon L. Harris

--
http://mail.python.org/mailman/listinfo/python-list


Using re.sub with %s

2010-08-18 Thread Brandon Harris

Having trouble using %s with re.sub

test = '/my/word/whats/wrong'
re.sub('(/)word(/)', r'\1\%s\2'%'1000', test)

return is /my/@0/whats/wrong

however if I cast a value with letters as opposed to numbers

re.sub('(/)word(/)', r'\1\%s\2'%'gosh', test)

return is /my/gosh/whats/wrong


Any help would be good. I've tried passing the value as an int, or 
recasting that value as something else, passing it as a raw string, 
removing the r and just double escaping the groups.


Brandon L. Harris

--
http://mail.python.org/mailman/listinfo/python-list


Multiline regex

2010-07-21 Thread Brandon Harris
I'm trying to read in and parse an ascii type file that contains 
information that can span several lines.

Example:

createNode animCurveTU -n test:master_globalSmooth;
   setAttr .tan 9;
   setAttr -s 4 .ktv[0:3]  101 0 163 0 169 0 201 0;
   setAttr -s 4 .kit[3]  10;
   setAttr -s 4 .kot[3]  10;
createNode animCurveTU -n test:master_res;
   setAttr .tan 9;
   setAttr .ktv[0]  103 0;
   setAttr .kot[0]  5;
createNode animCurveTU -n test:master_faceRig;
   setAttr .tan 9;
   setAttr .ktv[0]  103 0;
   setAttr .kot[0]  5;

I'm wanting to grab the information out in chunks, so

createNode animCurveTU -n test:master_faceRig;
   setAttr .tan 9;
   setAttr .ktv[0]  103 0;
   setAttr .kot[0]  5;

would be what my regex would grab.
I'm currently only able to grab out the first line and part of the 
second line, but no more.

regex is as follows

my_regexp = re.compile(createNode\ animCurve.*\n[\t*setAttr.*\n]*)

I've run several variations of this, but none return me all of the 
expected information.


Is there something special that needs to be done to have the regexp grab 
any number of the setAttr lines without specification?


Brandon L. Harris


--
http://mail.python.org/mailman/listinfo/python-list


Re: Multiline regex

2010-07-21 Thread Brandon Harris

what do you mean by slurp the entire file?
I'm trying to use regular expressions because line by line parsing will 
be too slow. And example file would have somewhere in the realm of 6 
million lines of code.


Brandon L. Harris

Rodrick Brown wrote:

Slurp the entire file into a string and pick out the fields you need.

Sent from my iPhone 4.

On Jul 21, 2010, at 10:42 AM, Brandon Harris brandon.har...@reelfx.com wrote:

  

I'm trying to read in and parse an ascii type file that contains information 
that can span several lines.
Example:

createNode animCurveTU -n test:master_globalSmooth;
  setAttr .tan 9;
  setAttr -s 4 .ktv[0:3]  101 0 163 0 169 0 201 0;
  setAttr -s 4 .kit[3]  10;
  setAttr -s 4 .kot[3]  10;
createNode animCurveTU -n test:master_res;
  setAttr .tan 9;
  setAttr .ktv[0]  103 0;
  setAttr .kot[0]  5;
createNode animCurveTU -n test:master_faceRig;
  setAttr .tan 9;
  setAttr .ktv[0]  103 0;
  setAttr .kot[0]  5;

I'm wanting to grab the information out in chunks, so

createNode animCurveTU -n test:master_faceRig;
  setAttr .tan 9;
  setAttr .ktv[0]  103 0;
  setAttr .kot[0]  5;

would be what my regex would grab.
I'm currently only able to grab out the first line and part of the second line, 
but no more.
regex is as follows

my_regexp = re.compile(createNode\ animCurve.*\n[\t*setAttr.*\n]*)

I've run several variations of this, but none return me all of the expected 
information.

Is there something special that needs to be done to have the regexp grab any 
number of the setAttr lines without specification?

Brandon L. Harris


--
http://mail.python.org/mailman/listinfo/python-list



--
http://mail.python.org/mailman/listinfo/python-list


Re: Multiline regex

2010-07-21 Thread Brandon Harris
At the moment I'm trying to stick with built in python modules to create 
tools for a much larger pipeline on multiple OSes.


Brandon L. Harris


Eknath Venkataramani wrote:



On Wed, Jul 21, 2010 at 8:12 PM, Brandon Harris 
brandon.har...@reelfx.com mailto:brandon.har...@reelfx.com wrote:


I'm trying to read in and parse an ascii type file that contains
information that can span several lines.

Do you have to use only regex? If not, I'd certainly suggest 
'pyparsing'. It's a  pleasure to use and very easy on the eye too, if 
you know what I mean.


 I'm wanting to grab the information out in chunks, so


--
Eknath Venkataramani


--
http://mail.python.org/mailman/listinfo/python-list


Re: RE: Multiline regex

2010-07-21 Thread Brandon Harris
I could make it that simple, but that is also incredibly slow and on a 
file with several million lines, it takes somewhere in the league of 
half an hour to grab all the data. I need this to grab data from many 
many file and return the data quickly.


Brandon L. Harris


Andreas Tawn wrote:

I'm trying to read in and parse an ascii type file that contains
information that can span several lines.
Example:

createNode animCurveTU -n test:master_globalSmooth;
setAttr .tan 9;
setAttr -s 4 .ktv[0:3]  101 0 163 0 169 0 201 0;
setAttr -s 4 .kit[3]  10;
setAttr -s 4 .kot[3]  10;
createNode animCurveTU -n test:master_res;
setAttr .tan 9;
setAttr .ktv[0]  103 0;
setAttr .kot[0]  5;
createNode animCurveTU -n test:master_faceRig;
setAttr .tan 9;
setAttr .ktv[0]  103 0;
setAttr .kot[0]  5;

I'm wanting to grab the information out in chunks, so

createNode animCurveTU -n test:master_faceRig;
setAttr .tan 9;
setAttr .ktv[0]  103 0;
setAttr .kot[0]  5;

would be what my regex would grab.
I'm currently only able to grab out the first line and part of the
second line, but no more.
regex is as follows

my_regexp =e.compile(createNode\ animCurve.*\n[\t*setAttr.*\n]*)

I've run several variations of this, but none return me all of the
expected information.

Is there something special that needs to be done to have the regexp
grab
any number of the setAttr lines without specification?

Brandon L. Harris



Aren't you making life too complicated for yourself?

blocks =]
for line in yourFile:
if line.startswith(createNode):
if currentBlock:
blocks.append(currentBlock)
currentBlock =line]
else:
currentBlock.append(line)
blocks.append(currentBlock)

Cheers,

Drea

  


--
http://mail.python.org/mailman/listinfo/python-list


Re: Multiline regex

2010-07-21 Thread Brandon Harris
Could it be that there isn't just that type of data in the file? there 
are many different types, that is just one that I'm trying to grab.


Brandon L. Harris


Andreas Tawn wrote:

I could make it that simple, but that is also incredibly slow and on a
file with several million lines, it takes somewhere in the league of
half an hour to grab all the data. I need this to grab data from many
many file and return the data quickly.

Brandon L. Harris



That's surprising.

I just made a file with 13 million lines of your data (447Mb) and read it with 
my code. It took a little over 36 seconds. There must be something different in 
your set up or the real data you've got.

Cheers,

Drea
  


--
http://mail.python.org/mailman/listinfo/python-list