473,549 Members | 2,346 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I Need A Placeholder

I'm trying to build a try/except case, and I want to have the except
function like such:

try:
# Do some code here
var = 1 # For example
except:
#Do nothing here

The only problem is if I leave a comment only in the except block, I
get an error back saying that the except block is not properly
formatted, since it has no content other than a comment.

So if anyone could suggest some code to put there as a placeholder
that would be wonderful.
Jun 27 '08 #1
10 1415
On Thu, 26 Jun 2008 10:03:47 -0700, Ampedesign wrote:
I'm trying to build a try/except case, and I want to have the except
function like such:

try:
# Do some code here
var = 1 # For example
except:
#Do nothing here

The only problem is if I leave a comment only in the except block, I
get an error back saying that the except block is not properly
formatted, since it has no content other than a comment.

So if anyone could suggest some code to put there as a placeholder
that would be wonderful.
"pass" would work fine.

try:
# Do something that can throw an exception
except:
pass

Jun 27 '08 #2
On Jun 26, 10:06*am, Daniel Mahoney <d...@catfolks. netwrote:
On Thu, 26 Jun 2008 10:03:47 -0700, Ampedesign wrote:
I'm trying to build a try/except case, and I want to have the except
function like such:
try:
* * * # Do some code here
* * * var = 1 * * * * # For example
except:
* * * #Do nothing here
The only problem is if I leave a comment only in the except block, I
get an error back saying that the except block is not properly
formatted, since it has no content other than a comment.
So if anyone could suggest some code to put there as a placeholder
that would be wonderful.

"pass" would work fine.

try:
* * *# Do something that can throw an exception
except:
* * *pass
Thanks. That will work perfectly.
Jun 27 '08 #3
Ampedesign wrote:
I'm trying to build a try/except case, and I want to have the except
function like such:

try:
# Do some code here
var = 1 # For example
except:
#Do nothing here

try:
# Do some code here
var = 1 # For example
except:
pass

Gary Herron

The only problem is if I leave a comment only in the except block, I
get an error back saying that the except block is not properly
formatted, since it has no content other than a comment.

So if anyone could suggest some code to put there as a placeholder
that would be wonderful.
--
http://mail.python.org/mailman/listinfo/python-list
Jun 27 '08 #4
Ampedesign <me**********@g mail.comwrote:
I'm trying to build a try/except case, and I want to have the except
function like such:

try:
# Do some code here
var = 1 # For example
except:
#Do nothing here

The only problem is if I leave a comment only in the except block, I
get an error back saying that the except block is not properly
formatted, since it has no content other than a comment.

So if anyone could suggest some code to put there as a placeholder
that would be wonderful.
Use the 'pass' statement.

But really, you should not have a bare except: if you are going to ignore a
specific exception that's fine, but don't ignore all exceptions. You'll
regret it.
Jun 27 '08 #5
On Jun 26, 10:08*am, Duncan Booth <duncan.bo...@i nvalid.invalid>
wrote:
Ampedesign <metalkeys...@g mail.comwrote:
I'm trying to build a try/except case, and I want to have the except
function like such:
try:
* * * # Do some code here
* * * var = 1 * * * * # For example
except:
* * * #Do nothing here
The only problem is if I leave a comment only in the except block, I
get an error back saying that the except block is not properly
formatted, since it has no content other than a comment.
So if anyone could suggest some code to put there as a placeholder
that would be wonderful.

Use the 'pass' statement.

But really, you should not have a bare except: if you are going to ignorea
specific exception that's fine, but don't ignore all exceptions. You'll
regret it.
This is true. Though I get a wide range of exceptions since I'm
downloading and parsing a file. I will get everything from a socket
error to an empty xml element.

In the future however, I will make separate exceptions.
Jun 27 '08 #6
Ampedesign wrote:
I'm trying to build a try/except case, and I want to have the except
function like such:

try:
# Do some code here
var = 1 # For example
except:
#Do nothing here

The only problem is if I leave a comment only in the except block, I
get an error back saying that the except block is not properly
formatted, since it has no content other than a comment.

So if anyone could suggest some code to put there as a placeholder
that would be wonderful.
except:
pass

is the usual technique there.

j

Jun 27 '08 #7
"Joshua Kugler" <jk*****@bigfoo t.comwrote in message
news:ma******** *************** **************@ python.org...
except:
pass

is the usual technique there.
Is there any other?
Jun 27 '08 #8
John Salerno wrote:
"Joshua Kugler" <jk*****@bigfoo t.comwrote in message
news:ma******** *************** **************@ python.org...
>except:
pass

is the usual technique there.

Is there any other?
Sure. Evaluating any side-effect free expression and ignoring the result
will work:

try:
# do somthing
except:
None

try:
# do something
except:
"I don't care about the exception."

Of course, using pass *is* the preferred method.

--
Carsten Haese
http://informixdb.sourceforge.net
Jun 27 '08 #9
John Salerno wrote:
"Joshua Kugler" <jk*****@bigfoo t.comwrote in message
news:ma******** *************** **************@ python.org...
>except:
pass

is the usual technique there.

Is there any other?
if 0: 42

Proof:
>>def cp(pass_):
.... return compile("try: 1/0\nexcept:\n %s" % pass_, "<nofile>", "exec")
....
>>cp("pass") == cp("if 0: 42")
True

:-)

Peter
Jun 27 '08 #10

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

Similar topics

2
4717
by: Mike Speak | last post by:
I have a user control that I want to use to render 4 menu items (retrieved from db) on the top of each of my asp.net pages. The user control defines a table, with one TR and one TD. Within the TD I have a placeholder defined: <asp:PlaceHolder ID="categoriesPlaceHolder" Runat="server" /> In the code behind of the user control, on the...
2
3051
by: Chad Crowder | last post by:
Is it possible to create a placeholder inside a template column of a datagrid? My goal is to use a placeholder, and during runtime add user controls to the placeholder as the items in the datagrid are being built. I've tried doing this with a simple link button, but I get the "Object Reference not set to an instance of an object" whenever I...
0
1582
by: shark | last post by:
I have a placeholder in a control that is in turn, used as a control in a placeholder in a form. I am getting a viewstate error so I believe I have to clear my placeholder before I load the control within the control. How to I address this placeholder to clear it? The following gives me a null object error: PlaceHolder myPlaceHolder =
0
1653
by: RSB | last post by:
Hi Every one, i am trying to create a UserControl and i am passing a Array of strings to it. Now based on the Array elements i am creating the LinkButtons Dynamically. I am also passing a Event to this control and Lining the OnClick event of these LinkButtons to this Event. (Which works fine). Now the Thing which i cannot achieve is i want...
7
9070
by: Brad Baker | last post by:
I am trying to programmatically set a placeholder control in csharp which is nested inside a repeater control between <ItemTemplateand </ItemTemplate> tags, however I am running into problems. I've tried several different approaches for finding the placeholder: This: MyControl = this.FindControl("$form$tabs_repeater$PlaceHolder1"); ...
0
7546
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...
0
7740
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7503
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...
0
7830
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...
0
6071
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...
1
5387
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...
0
3496
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1082
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.