:
(options,args) = parser.parse_args()
len(options) != 1 or len(options) 2:
print Incorrect number of arguments passed.
How do I accomplish it ?
Regards,
rrs
- --
Ritesh Raj Sarraf
RESEARCHUT -- http://www.researchut.com
Stealing logics from one person is plagiarism, stealing from many
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Marc 'BlackJack' Rintsch on Monday December 5 2005 03:24 wrote:
In [EMAIL PROTECTED], Ritesh Raj
Sarraf wrote:
My program uses mostly option arguments hence my len(args) value is
always zero. I need to check if the user has passed the correct
have multiple options but I have parser.set_defaults() for each of them.
Regards,
rrs
- --
Ritesh Raj Sarraf
RESEARCHUT -- http://www.researchut.com
Stealing logics from one person is plagiarism, stealing from many is
research.
Necessity is the mother of invention.
Note: Please CC me. I'm
On Tue, 6 Dec 2005, Peter Otten wrote:
Ritesh Raj Sarraf wrote:
I'm using this for option arguments which are mutually inclusive.
But I want the user to pass atleast one option argument for the program
to function properly.
For example, I have an option --fetch-update which requires a file
a default value. So I want to check what the user has
passed.
But unfortunately the args variable has 0 as its value always.
Is my way (up till now) of using optparse logically incorrect or improper ?
Regards,
rrs
- --
Ritesh Raj Sarraf
RESEARCHUT -- http://www.researchut.com
Stealing logics from
(temp.headers['Content-Length'])
#prog = progressBar(0, lastval, 77)
#
#for x in range(101):
#prog.updateAmount(x)
#print prog, \r, time.sleep(0.5)
#
#data = open(sFile,'wb')
#data.write(temp.read())
#data.close()
#temp.close()
Regards,
Ritesh
- --
Ritesh Raj Sarraf
RESEARCHUT -- http
()
temp.close()
Thanks,
Ritesh
Ritesh Raj Sarraf on Sunday 15 Jan 2006 12:55 wrote:
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi,
In urllib.urlretrieve I can use reporthook to implement a progress bar.
But in urllib2.urlopen I can't.
I have to use urllib2.urlopen because
Hi,
Following is the code:
def walk_tree_copy(sRepository, sFile, sSourceDir, bFound = None):
try:
if sRepository is not None:
for name in os.listdir(sRepository):
path = os.path.join(sRepository, name)
if os.path.isdir(path):
Thanks to everyone. It is really the best place and the best people to
learn from.
Here's what I followed from the discussion:
def files(root):
for path, folders, files in os.walk(root):
for file in files:
yield path, file
def copy_first_match(repository, filename,
Please Help!
rrs
- --
Ritesh Raj Sarraf
RESEARCHUT -- http://www.researchut.com
Gnupg Key ID: 04F130BC
Stealing logic from one person is plagiarism, stealing from many is
research.
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.5 (GNU/Linux)
iD8DBQFCRcCk4Rhi6gTxMLwRAlb2AJ0fB3V5ZpwdAiCxfl
if it downloaded the desired file.
I think my problem is fixable in urllib.urlopen, I just find
urllib.urlretrieve more convenient and want to know if it can be done with
it.
Thanks for responding.
rrs
- --
Ritesh Raj Sarraf
RESEARCHUT -- http://www.researchut.com
Gnupg Key ID: 04F130BC
Stealing logic from
cetera. That is why I'm sticking strictly to python libraries.
The second suggestion sounds good. I'll look into that.
Thanks,
rrs
- --
Ritesh Raj Sarraf
RESEARCHUT -- http://www.researchut.com
Gnupg Key ID: 04F130BC
Stealing logic from one person is plagiarism, stealing from many is
research
Hi,
I've been very confused about why this doesn't work. I mean I don't see any
reason why this has been made not to work.
class Log:
def __init__(self, verbose, lock = None):
if verbose is True:
self.VERBOSE = True
else: self.VERBOSE = False
if lock
On Aug 11, 3:17 am, James Stroud [EMAIL PROTECTED] wrote:
You do realize your import statement will only be called for nt and dos
systems don't you?
Yes. I would like to load a Windows Python Module (which is, say a
specific implementation for Windows only) in such a condition where I
find
Bruno Desthuilliers wrote:
Ritesh Raj Sarraf a écrit :
if lock is None or lock != 1:
self.DispLock = False
else:
self.DispLock = threading.Lock()
self.lock = True
if os.name == 'posix':
self.platform = 'posix
Bruno Desthuilliers wrote:
Ritesh Raj Sarraf a écrit :
The initializer will be called *each time* you instanciate the class.
And nothing prevents client code from calling it explicitelly as many
times as it wants - ok, this would be rather strange, but this is still
technically possible
Steve Holden wrote:
Ritesh Raj Sarraf wrote:
class Log:
def __init__(self, verbose, lock = None):
if verbose is True:
self.VERBOSE = True
else: self.VERBOSE = False
Better:
self.VERBOSE = verbose
or, if you suspect verbose might pass in a mutable
Bruno Desthuilliers wrote:
What's leading you to conclude the import isn't being executed? You
realise, I trust, that the module's code will only be executed on the
first call to __init__()?
Well. Putting it in a try inside __init__() doesn't do anything.
This would be highly suprising.
Neil Cerutti wrote:
If you want an import inside an __init__ to run, you must call
the __init__ function that contains it.
Doesn't __init__ get called automatically ?
I thought __init__ was required to be called explicitly only when you were
doing inheritance and wanted to pass separate values
Neil Cerutti wrote:
Doesn't __init__ get called automatically ?
It gets called automatically when you construct an instance of
the class in which it's defined.
I am a little confused by your statements now.
In my earlier posts in the same thread, I gave some code example which was
On Aug 15, 11:42 pm, Neil Cerutti [EMAIL PROTECTED] wrote:
On 2007-08-15, Ritesh Raj Sarraf [EMAIL PROTECTED] wrote:
Or am I terribly missing something that you are trying to tell ?
I didn't see log = Log() in your example. Sorry for the
excursion.
Are you sure os.name is 'posix' on your
On Aug 16, 12:16 am, Ritesh Raj Sarraf [EMAIL PROTECTED] wrote:
On Aug 15, 11:42 pm, Neil Cerutti [EMAIL PROTECTED] wrote:
On 2007-08-15, Ritesh Raj Sarraf [EMAIL PROTECTED] wrote:
Or am I terribly missing something that you are trying to tell ?
I didn't see log = Log() in your example
Steve Holden wrote:
Ritesh Raj Sarraf wrote:
On Aug 16, 12:16 am, Ritesh Raj Sarraf [EMAIL PROTECTED] wrote:
On Aug 15, 11:42 pm, Neil Cerutti [EMAIL PROTECTED] wrote:
[...]
Oops!!! Looks like I completely missed this. It _did_ print the error
message.
Apologies to all for not keeping
Can you please point some good documents (need not be Python specific)
on best practices with writing code this way ?
Thanks,
Ritesh
--
http://mail.python.org/mailman/listinfo/python-list
Hi,
I need a little help in understanding how Namespaces and scoping works with
Classes/Functions in Python.
Here's my code:
class FetchData:
def __init__(self, dataTypes=[foo, bar, spam], archive=False):
self.List = []
self.Types = dataTypes
if
Hi,
I have a funtion named unzipper() which does the work of unzipping the
files.
Is there a way I can identify what is the type of the file which'll be
passed to unzipper().
If yes, I'll be able to make out if it's a zip file or a tar or a bz2
file.
Thanks,
Ritesh
--
But isn't there any library function ?
Something like
XX.filetype(name)
Directory
File-Tar
File-Zip
File-MPEG
Ritesh
Maric Michaud wrote:
Le Mercredi 14 Juin 2006 11:22, Ritesh Raj Sarraf a écrit :
Hi,
I have a funtion named unzipper() which does the work of unzipping the
files
Also,
f = file ('some_file.jpg')
throws an error.
str object is not callable
Ritesh
Maric Michaud wrote:
Le Mercredi 14 Juin 2006 11:22, Ritesh Raj Sarraf a écrit :
Hi,
I have a funtion named unzipper() which does the work of unzipping the
files.
Is there a way I can identify what
Hi,
I've got a problem here.
def compress_the_file(zip_file_name, files_to_compress, sSourceDir):
Condenses all the files into one single file for easy transfer
try:
import zipfile
except ImportError:
sys.stderr.write(Ai! module not found.\n)
try:
Hi,
I'm having some minor problems with optparse. I'm just worried that
someone shouldn't say that multiple argument feature isn't implemented
in optpartse.
How to tackle multiple arguments to an option ?
As far as I dug, I've found that 1 arguments are being ignored.
parser.add_option(,
Ritesh Raj Sarraf wrote:
Hi,
I'm having some minor problems with optparse. I'm just worried that
someone shouldn't say that multiple argument feature isn't implemented
in optpartse.
How to tackle multiple arguments to an option ?
As far as I dug, I've found that 1 arguments are being
Ritesh Raj Sarraf wrote:
I just noticed that the args variable is holding values b and c.
the args variables comes from:
(options, args) = parser.parse_args()
I guess I only need to figure out now is why args isn't storing
argument a also...
Ritesh
I fixed it, I guess.
parser.add_option
Simon Percivall wrote:
It might do you good to read the documentation instead of blindly
experimenting.
Anyway,
parser.add_option(, --my-option, nargs=3)
http://docs.python.org/lib/optparse-standard-option-actions.html
That won't help because by design of my program, I can't limit the
Fredrik Lundh wrote:
Ritesh Raj Sarraf wrote:
http://docs.python.org/lib/optparse-standard-option-actions.html
That won't help because by design of my program, I can't limit the
number of arguments a user can pass to it.
do you want options, arguments, or are you just somewhat
Hi,
The program downloads the files from the internet and compresses them
to a single zip archive using compress_the_file().
Upon running syncer() which calls the decompress_the_file(), the first
iteration succeeds. But upon second iteration, I get an IOError
exception with the message:
)
console.setLevel(logging.INFO)
console_formatter = logging.Formatter('%(message)s')
console.setFormatter(console_formatter)
logger.addHandler(conerr)
logger.addHandler(console)
logger.info(Ritesh Raj Sarraf.\n)
logger.warning(Ricky Raj Sarraf.\n)
Hi,
When I execute the above code, logger.info()'s messages
Ritesh Raj Sarraf wrote:
import os, sys, logging
logger = logging.getLogger(my_app)
I tried this code:
import logging, sys
# set up logging to file - see previous section for more details
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(name)-12s
is supported. For
multithreaded applications, in PyDev, you'll see all the threads listed.
Then you can use each thread and proceed with debugging the code.
Learning Eclipse might take some time but that's worth it.
HTH,
Ritesh
--
Ritesh Raj Sarraf
RESEARCHUT - http://www.researchut.com
Necessity
Vinay Sajip wrote:
It's usual to rely on logger levels and to set handler levels for
additional refinement of what goes to a particular handler's
destination.
The problem is that for StreamHandler, logging module logs to
sys.stderr.
I want to use the logging feature for most of the messages
Peter Otten wrote:
You can achieve the desired behaviour by adding a custom Filter:
import sys
import logging
logger = logging.getLogger(my_app)
logger.setLevel(logging.DEBUG)
class LevelFilter(logging.Filter):
def __init__(self, level):
self.level = level
def
Hi,
I have a class defined in a file called foo.py
In bar.py I've imported foo.py
In bar.py's main function, I instantiate the class as follows:
log = foo.log(x, y, z)
Now in main I'm able to use log.view(), log.error() et cetera.
But when I call the same method from some functions which are
Steve Holden wrote:
Ritesh Raj Sarraf wrote:
But when I call the same method from some functions which are in
bar.py, it fails giving me the following error:
NameError: global name 'log' is not defined
Well, that's preumbaly because your
log = foo.log(x, y, z)
statement
log = foo.log(x, y, z)
Resulting line is:
log = foo.log(x, y, z)
global log
Making the instance log global makes it accessible to all the
functions.
Now I have only one question, Is this a correct way to do it ? Or are
there better way ?
Ritesh
--
Hi,
I have some basic doubts about thread.
I have a list which has items in it which need to be downloaded from
the internet.
Let's say list is:
list_items[] which has 100 items in it.
I have a function download_from_web() which does the work of
downloading the items from the web. It does
()
counter += 1
i += 1
counter = 0
join_i = i - 3
while counter 3:
threads[join_i].join()
counter += 1
join_i += 1
Is this correct ? Comments!!
Ritesh
Duncan Booth wrote:
Ritesh Raj Sarraf wrote:
I'm
finished:
for t in thread_pool:
requestQueue.put(None)
for t in thread_pool:
t.join()
Thanks a lot for your replies.
Ritesh
--
Ritesh Raj Sarraf
RESEARCHUT - http://www.researchut.com
Necessity is the mother of invention.
Stealing logic from one person is plagiarism, stealing from many
And people, Is there any documentation on Python Threads or Threads in general.
It'd be of great help to really understand.
Ritesh
Ritesh Raj Sarraf on Thursday 27 Jul 2006 16:37 wrote:
Is this the correct way of threading applications ?
This is the first time I'd be doing threading. So
.
Is this all correct ?
I also do have a couple of questions more which would be related to locks. But
I'd post them once I get done with this part.
Thanks,
Ritesh
--
Ritesh Raj Sarraf
RESEARCHUT - http://www.researchut.com
Necessity is the mother of invention.
Stealing logic from one person is plagiarism
on Thursday 27 Jul 2006 22:33 wrote:
Ritesh Raj Sarraf wrote:
[snip]
for item in list_items:
download_from_web(item)
This way, one items is downloaded at a time.
I'm planning to implement threads in my application so that multiple
items can be downloaded concurrently. I want the thread
Simon Forman wrote:
One other question I had,
If my user passes the --zip option, download_from_web() internally (when the
download is successful) zips the downloaded data to a zip file. Since in
case
of threading there'll be multiple threads, and say if one of the thread
completes 2
Simon Forman wrote:
The other threads will just take the next request from the Queue and
process it. They won't care what the one thread is doing,
downloading, zipping, whatever.
As I mentioned in my previous post, the other threads will also have to
go through the same zip the file if the
Gerhard Fiedler wrote:
Rather than downloading and zipping in the same thread, you could run
multiple threads like you're doing that only download files, and one
zip-it-all-up thread. After downloading a file, the download threads place
a message in a queue that indicates the file they have
Carl Banks wrote:
If you have multiple threads trying to access the same ZIP file at the
same time, whether or not they use the same ZipFile object, you'll have
trouble. You'd have to change download_from_web to protect against
simultaneous use. A simple lock should suffice. Create the
:
compress_the_file(zip_type_file, sFile, sSourceDir)
os.unlink(sFile)
finally:
ziplock.release()
--
Ritesh Raj Sarraf
RESEARCHUT - http://www.researchut.com
Necessity is the mother of invention
.
Try moving ziplock = threading.Lock() out of the function, so
your code might read, in part:
ziplock = threading.Lock()
def run(request, response, func=copy_first_match):
# And so on...
Thanks. That did it. :-)
Ritesh
--
Ritesh Raj Sarraf
RESEARCHUT - http://www.researchut.com
Necessity
that the progress bar gets over-written by
the download progress of files from other threads.
I believe my change has to go into the progress bar class to make it thread
aware.
Are they any docs/suggestions on how to implement progress bars along with
threads ?
Thanks,
Ritesh
--
Ritesh Raj Sarraf
RESEARCHUT
, and tell the thread which bar to update.
Yes, you're correct. That's what I'm also suspecting. I tried to do some minor
changes but couldn't succeed.
Request you to, if you reply with code, give a little explanation so that I can
understand and learn from it.
Thanks,
Ritesh
--
Ritesh Raj Sarraf
if that's not true.
My question is, in a code example like this which is threaded, does the locking
mechanism work correctly ?
Or are two different locks being acquired ?
Thanks,
Ritesh
--
Ritesh Raj Sarraf
RESEARCHUT - http://www.researchut.com
Necessity is the mother of invention.
Stealing
of seconds for the zip to
complete. During those couple of seconds, if another thread's file (a
couple kb) gets downloaded/copied, will it wait for the lock to be
released or will it create another lock ?
Thanks,
Ritesh
Dennis Lee Bieber wrote:
On Wed, 11 Oct 2006 18:39:32 +0530, Ritesh Raj
Hi,
I have, for very long, been trying to find a consistent solution (which
could work across major python platforms - Linux, Windows, Mac OS X)
for the following problem.
I have a function which downloads files from the web. I've made the
function threaded. I'm trying to implement a progress
--
Ritesh Raj Sarraf
RESEARCHUT - http://www.researchut.com
Necessity is the mother of invention.
Stealing logic from one person is plagiarism, stealing from many is
research.
The great are those who achieve the impossible, the petty are those who
cannot - rrs
pgp4GnEOe0frx.pgp
Description: PGP
on a single line. Probably the apt developers also
might have run into the same issue and hence settled down with this
workaround.
Thanks,
Ritesh
Dennis Lee Bieber wrote:
On Tue, 28 Nov 2006 15:15:28 +0530, Ritesh Raj Sarraf
[EMAIL PROTECTED] declaimed the following in comp.lang.python
somebody please help about where I'm doing any mistake ?
Thanks,
Ritesh
--
Ritesh Raj Sarraf
RESEARCHUT - http://www.researchut.com
Necessity is the mother of invention.
Stealing logic from one person is plagiarism, stealing from many is research.
The great are those who achieve the impossible
Gabriel Genellina wrote:
En Thu, 15 Mar 2007 18:31:29 -0300, Ritesh Raj Sarraf [EMAIL PROTECTED]
escribió:
I'm not sure if there's something wrong in the code mentioned above or
is it
really a lock problem.
Try to break the code into smaller pieces to see what is wrong. It's too
long
to be the same.
Ritesh
--
Ritesh Raj Sarraf
RESEARCHUT - http://www.researchut.com
Necessity is the mother of invention.
Stealing logic from one person is plagiarism, stealing from many is research.
The great are those who achieve the impossible, the petty are those who
cannot - rrs
--
http
--
Ritesh Raj Sarraf
RESEARCHUT - http://www.researchut.com
Necessity is the mother of invention.
Stealing logic from one person is plagiarism, stealing from many is research.
The great are those who achieve the impossible, the petty are those who
cannot - rrs
--
http://mail.python.org/mailman/listinfo
is because the output can be huge and useless.
Then I do some pattern matching on that file and filter my data and then delete
it.
If you think I still am missing something important, request you to describe it.
Thanks,
Ritesh
--
Ritesh Raj Sarraf
RESEARCHUT - http://www.researchut.com
Necessity
New submission from Ritesh Raj Sarraf r...@researchut.com:
Whey I do a help (python-module), I get the help text as follows:
Help on module tempfile:
NAME
tempfile - Temporary files.
FILE
/usr/lib/python2.5/tempfile.py
MODULE DOCS
http://www.python.org/doc/2.5.4/lib/module
Changes by Ritesh Raj Sarraf r...@researchut.com:
--
type: - feature request
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6824
___
___
Python
Ritesh Raj Sarraf r...@researchut.com added the comment:
Take help os or help os.fork for example.
WIth the help output that they provide, how am I supposed to know that
os.fork is only supported on Unix.
We can also go with the assumption that the modules shipped are
cross-platform
Ritesh Raj Sarraf r...@researchut.com added the comment:
I never said that I think it is not cross-platform.
My point is, it should be good to list down a module's dependency in the
python help docs.
Like:
tempfile
Supported Platforms: ALL
Exception: On Platform foo, feature tempfile.bar
New submission from Ritesh Raj Sarraf r...@researchut.com:
Shoudl argparse be included in the Python Standard Library.
I know we already have getopt and optparse but optparse doesn't
support many features easily. (like options without hyphen, nargs=*)
Here a little about argparse:
argparse
Ritesh Raj Sarraf r...@researchut.com added the comment:
From the author, Steven Berthard:
Sorry about the delay - conferences and moving means that I haven't
had as much time for argparse as I'd like. Basically, the way things
get into the Python standard library
Ritesh Raj Sarraf r...@researchut.com added the comment:
Thanks for the link. As a user, I see many of the features that argparse
brings, to be helpful.
Since they are missing in optparse, and since it doesn't look like
argparse will be included, should I open new bugs for those features
Ritesh Raj Sarraf r...@researchut.com added the comment:
I'm not sure about the design part, but as a user, I find both to have very
similar interfaces.
argparse is better because it handles nargs=*. This has long been
asked in optparse. Positional arguments is something I wanted recently
75 matches
Mail list logo