473,387 Members | 1,485 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Encapsulating conditional execution based on list membership - how do you do it?

I have a series of scripts which retrieve files. None of these scripts
should continue if the file to be retrieved already exists in the
archive. Here is the code:

if f in path(self.storage.archive).files('*'):
print f, "exists in archive. Not continuing"
sys.exit()
self.storage is a class which gives me object-oriented access to the
filesystem directories that will be manipulated by the script. E.g.
self.storage.archive is a string which refers to a certain directory.
Initializing this object initializes all the members (input, archive,
output, workfiles) and makes all the correct directories.

ok, so I'm thinking of adding a method to the storage class so I can do
this:

self.storage.archive_has(f, print_msg=True) and sys.exit()

but really there is no need to hardcode which storage directory. So I'm
thinking:

self.storage.memberof('archive', f, print_msg=Tree) and sys.exit()
Is that the best solution you can think of?

Dec 11 '06 #1
1 988
At Monday 11/12/2006 12:23, metaperl wrote:
>ok, so I'm thinking of adding a method to the storage class so I can do
this:

self.storage.archive_has(f, print_msg=True) and sys.exit()

but really there is no need to hardcode which storage directory. So I'm
thinking:

self.storage.memberof('archive', f, print_msg=Tree) and sys.exit()
Is that the best solution you can think of?
This is just _my_ opinion, of course.
I don't like the construct "blablabla() and sys.exit()" or
"blablabla() or sys.exit()", I prefer an explicit check "if not
blablabla(): exit()"
I'm not sure what you mean by "archive" but instead of a string, make
it an object so you can write self.storage.archive.has_file(f). The
check should do just *that*, return a boolean without side effects;
if you want to print a message, make the caller print it.
If you alias .has_file as .__contains__, you could also write: if f
in self.storage.archive, which looks even better.
--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ˇgratis!
ˇAbrí tu cuenta ya! - http://correo.yahoo.com.ar
Dec 12 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Bozo Schmozo | last post by:
Greetings! I've searched groups.google.com already to see if I can determine if using PHP/MySQL (if needed) for a web site I wish to develop. As the subject indicated, it will be a content...
1
by: John Davis | last post by:
I want to display credit card fields when the user selects the option paid membership. If user selects the option free membership, then the credit card text field will disappear. Here's the code I...
7
by: Guy Hocking | last post by:
Hi there, I have a problem in my ASP/SQL Server application i am developing, i hope you guys can help. I have a ASP form with list boxes populated by SQL tables. When a user selects a value...
4
by: CGuy | last post by:
Hi, I have an ASPX page which has a datagrid and this datagrid is bound to a Custom Collection. sample code this.DataGrid1.DataSource = UserManager.Users; this.DataGrid1.DataBind();
3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
5
by: Alan Roberts | last post by:
Is it possible to have conditional references and code execution in csharp? I have an app that plays Windows Media asx streams. It requires WMP 9+ to be installed for this to work and so this is a...
2
by: jodyblau | last post by:
I'm not certain that what I am trying to do is possible; in any event I haven't been able to figure it out. Here is what I am trying to do: I have one table that has a list of cases I'm working...
44
by: petermichaux | last post by:
Hi, I have been using the following line of code to create an object called "Serious" if it doesn't already exist. if (Serious == null) {var Serious = {};} This works in the scripts I use...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.