473,769 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Any tips/comments on my code sample

Just wondering if anyone could give me advice on handling potential
error conditions in python, it seems that exceptions are used alot more
for this stuff than in other languages.

I have provided a code sample giving an example of a first attempt at
using them (in python anyway) and also I have given an example of using
the logging module I intend to use to replace all the print
statements... it seems hassle to set up, but I think logging can
provide good flexibility. - just wondering if you could give comments
on my use of exceptions and the logging module (and my code in general
as i'm a relative newbie), and whether the logging module can handle
the case where you have threaded code (handling file locking on the log
files etc.)

Cheers

def Configure_Loggi ng():
print "configurin g logging"
logger = logging.getLogg er("CT_Deploy" )
logger.setLevel (logging.DEBUG)
ch = logging.StreamH andler()
ch.setLevel(log ging.DEBUG)
formatter = logging.Formatt er("%(asctime) s - %(levelname)-8s -
%(name)s - %(message)s")
ch.setFormatter (formatter)
logger.addHandl er(ch)

logger.debug("L ogging configured")
def Do_DB_Stuff(dep lo_num):

logger = logging.getLogg er("CT_Deploy_l ogger.Do_DB_Stu ff")

sql_list = ["alter table deplo_%s move tablespace MAP" % deplo_num,
"create index deplo_%s_esz on deplo_%s(esz) tablespace
cadidx" % (deplo_num, deplo_num),
"analyze table deplo_%s estimate statistics for all
columns" % deplo_num]

db_list = ["db1", "db2", "db3", "db4"]

for db in db_list:
try:
#connect_string = "usr/pass@%s" % db
#conn = cx_Oracle.conne ct(connect_stri ng)
#cur = conn.cursor()
print "\n\nConnec ted to %s..." % db
except cx_Oracle.Datab aseError:
print "\n\nUnable to connect to %s" % db
continue

try:
try:
for sql in sql_list:
#cur.execute(sq l % CT_deplo_num)
print "\tSuccess: executing '%s' against %s" %
(sql, db)
except cx_Oracle.Datab aseError:
print "\tFailure: executing '%s' against %s" % (sql,
db)
print "\tROLLING BACK..."
conn.rollback()
else:
conn.commit()
finally:
cur.close()
conn.close()

def main():
Configure_Loggi ng()
deplo_num = raw_input("plea se enter deplo num...")
Do_DB_Stuff(dep lo_num)
if __name__ == "__main__":
main()

Jul 25 '06 #1
0 1283

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

Similar topics

0
3948
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest version of this document can be found at: http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download
3
2094
by: Kenneth P | last post by:
Hi, I have a very good book on asp.net Sams ASP.NET Tips, Tutorials and Code ISBN 0-672-32143-2 and is trying to teach myself from examples from this book Chapter 16. Anyway I come quite close when trying to run one example but then I get this message I don't understand: "This .resources file shouldn't be used with this reader. Your resource
6
1679
by: planetthoughtful | last post by:
Hi All, I've written my first piece of practical Python code (included below), and would appreciate some comments. My situation was that I had a directory with a number of subdirectories that contained one or more zip files in each. Many of the zipfiles had the same filename (which is why they had previously been stored in separate directories). I wanted to bring all of the zip files (several hundrd in total) down to the common parent...
3
3340
by: tom | last post by:
I'm trying to read in image data using the filesystemobject. I am able to read the comments field for all file types it seems, except the ones I want, .gif .jpg and .bmp. Is it possible to do this?! If so what might I need to do? Thanks! here is the script im using to loop through each possible sub field:
6
1915
by: Lex Hider | last post by:
Hi, Apologies if this is against etiquette. I've just got my first python app up and running. It is a podcast aggregator depending on feedparser. I've really only learnt enough to get this up and running. Any tips on the code quality and use of python would be appreciated. I've got a feeling the overall structure is up the creek. approx 220 LOC. file: GodCast.py
98
4625
by: tjb | last post by:
I often see code like this: /// <summary> /// Removes a node. /// </summary> /// <param name="node">The node to remove.</param> public void RemoveNode(Node node) { <...> }
3
1401
by: Mark C | last post by:
Hi I was in the progress of developing a web site whereby developers can do free online tests on various programming languages. After initial feedback I managed to fix quite a few issues and changed the look and feel. I would just like some futher comments\tips\hints or feedback The site is http://www.quiznetonline.com
28
2015
by: Hapary | last post by:
Hello all, I remember that I saw a piece of code a few years ago, it was using a combination of both /* */ and // such that you could determine the compile type of the source code. I don't remember exactly what was happening, but I assume it was something like if the source code was being compiled by a c compiler the value of a variable became 1 and if it was compiled with c++ compiler the value became 0. Do you know how can I find that...
0
9583
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9860
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6668
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5297
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.