Questions tagged [except]

Used for the MS .NET LINQ Except() method and the Python except keyword for exception handling. Use the tag sql-except for questions related to the SQL operator EXCEPT

except
Filter by
Sorted by
Tagged with
929 votes
15 answers
1.5m views

python exception message capturing

import ftplib import urllib2 import os import logging logger = logging.getLogger('ftpuploader') hdlr = logging.FileHandler('ftplog.log') formatter = logging.Formatter('%(asctime)s %(levelname)s %(...
Hellnar's user avatar
  • 63.5k
300 votes
35 answers
372k views

Safe method to get value of nested dictionary

I have a nested dictionary. Is there only one way to get values out safely? try: example_dict['key1']['key2'] except KeyError: pass Or maybe python has a method like get() for nested ...
Arti's user avatar
  • 7,650
136 votes
11 answers
273k views

Multiple try codes in one block

I have a problem with my code in the try block. To make it easy this is my code: try: code a code b #if b fails, it should ignore, and go to c. code c #if c fails, go to d code d ...
arvidurs's user avatar
  • 2,963
123 votes
4 answers
112k views

Using python "with" statement with try-except block

Is this the right way to use the python "with" statement in combination with a try-except block?: try: with open("file", "r") as f: line = f.readline() except IOError: <whatever>...
minou's user avatar
  • 16.3k
121 votes
3 answers
107k views

What is wrong with using a bare 'except'?

I tried making a function to check if an image is displayed on the screen using PyAutoGui and came up with this: def check_image_on_screen(image): try: pyautogui.locateCenterOnScreen(...
CaioRamaglio's user avatar
  • 1,337
59 votes
7 answers
202k views

Catch KeyError in Python

If I run the code: connection = manager.connect("I2Cx") The program crashes and reports a KeyError because I2Cx doesn't exist (it should be I2C). But if I do: try: connection = manager.connect(...
spizzak's user avatar
  • 1,127
49 votes
6 answers
76k views

Python try block does not catch os.system exceptions

I have this python code: import os try: os.system('wrongcommand') except: print("command does not work") The code prints: wrongcommand: command not found Instead of command does not work. Does ...
Cinder's user avatar
  • 1,609
38 votes
2 answers
101k views

What's wrong with my except? [duplicate]

I've got a SyntaxError on my except: try: opts, args = getopt.getopt(sys.argv[1:], 'P:D:H:d:u:p:nvhmJi:c:Ml:TB:', ['host=', 'port=', 'directory=', 'user=', 'password=', '...
lagarkane's user avatar
  • 945
37 votes
3 answers
62k views

How does LINQ Except work? [duplicate]

Possible Duplicate: LINQ find differences in two lists I want to find a difference between 2 series. So I am using Except in the LINQ statement. But Except seems to work only when the first ...
gunnerz's user avatar
  • 1,906
27 votes
8 answers
38k views

C# Linq intersect/except with one part of object

I've got a class: class ThisClass { private string a {get; set;} private string b {get; set;} } I would like to use the Intersect and Except methods of Linq, i.e.: private List<ThisClass> ...
David Archer's user avatar
  • 2,028
20 votes
5 answers
33k views

Invalid syntax (SyntaxError) in except handler when using comma

I have this code: @app.route('/login/', methods=['GET', 'POST']) def login(): error = None if request.method == 'POST': session['username'] = request.form['username'] session['...
user avatar
20 votes
5 answers
46k views

Using Linq Except not Working as I Thought

List1 contains items { A, B } and List2 contains items { A, B, C }. What I need is to be returned { C } when I use Except Linq extension. Instead I get returned { A, B } and if I flip the lists ...
Schanckopotamus's user avatar
14 votes
5 answers
5k views

Repetitive Try and Except Clauses

I've created a bunch of functions and I need very similar except clauses in all of them, but I hate having so many lines of try and except clauses and the same code inside of each function. For ...
crunkchitis's user avatar
14 votes
3 answers
26k views

How do I select all inputs except under a specific id?

What I want to do is to select all the inputs buttons on the document, except those that reside under a specific id. Example: <body> <input type="button"> <div id="something"> ...
Jose A's user avatar
  • 10.6k
13 votes
3 answers
34k views

Compare two SQL tables and return missing ids?

I have two simple tables: (here only the "id" column) table1: id 1 2 3 4 table2: id 2 4 the sql query should compare the two tables for missing "id" in table2 and return: 1,3 any ...
MilMike's user avatar
  • 12.7k
13 votes
3 answers
22k views

How to use linq `Except` with multiple properties with different class?

I am trying to learn the Linq/Lambda expressions and was stuck at somewhere. What I was Doing I have created two classes with properties which have some common properties in them. The classes are ...
user2745246's user avatar
13 votes
2 answers
15k views

What is the analogue of EXCEPT clause in SQL in Pandas?

I have a sample pandas dataframe df: col1 col2 col3 col4 0 a 1.0 2.0 3 1 b NaN NaN 6 2 c NaN 8.0 9 3 d NaN ...
im7's user avatar
  • 673
10 votes
4 answers
114k views

File Open Function with Try & Except Python 2.7.1

def FileCheck(fn): try: fn=open("TestFile.txt","U") except IOError: print "Error: File does not appear to exist." return 0 I'm trying to make a ...
O.rka's user avatar
  • 30.7k
10 votes
2 answers
14k views

Does EXCEPT execute faster than a JOIN when the table columns are the same

To find all the changes between two databases, I am left joining the tables on the pk and using a date_modified field to choose the latest record. Will using EXCEPT increase performance since the ...
Anthony Kiskaden's user avatar
9 votes
4 answers
966 views

Confused about try/except with custom Exception

My code: class AError(Exception): print 'error occur' for i in range(3): try: print '---oo' raise AError except AError: print 'get AError' else: print '...
kker neo's user avatar
  • 133
9 votes
6 answers
11k views

How to remove nested keys from a hash list in Rails

I am now trying for some hours to remove a nested hash key of a hash list. I saw many solution non-nested hashs wich looks like this: sample_hash = {"key1" => "value1", "key2" => "value2"} ...
user1367922's user avatar
8 votes
3 answers
18k views

How to insert into a static table using EXCEPT?

I am developing an SSMS 2008 R2 T-sql query. Currently my query looks like: INSERT rd_scs_only_clients SELECT DISTINCT en.clientid_c FROM cd.enrollments en WHERE en.agency_c in ('SCCR','SCRP') AND ...
salvationishere's user avatar
8 votes
1 answer
7k views

Delphi Exception handling problem with multiple Exception handling blocks

I'm using Delphi Pro 6 on Windows XP with FastMM 4.92 and the JEDI JVCL 3.0. Given the code below, I'm having the following problem: only the first exception handling block gets a valid instance of E....
Robert Oschler's user avatar
8 votes
1 answer
28k views

Python empty list Exception [closed]

I have this function: def foo(): a = [] if not a: print "empty" return None else: print "not empty" return a Is there any Exception that do the same? Just ...
ddepablo's user avatar
  • 677
8 votes
5 answers
14k views

Python: Multiple try except blocks in one?

Is there a neat way to have multiply commands in the try block so that it basically tries every single line without stopping as soon as one command yields an error? Basically I want to replace this: ...
user4911943's user avatar
7 votes
3 answers
14k views

LINQ Map one type to another

I need to find difference between to sets. Classes ,comprising the sets, are different but have same type of fields. To be able to use Except method ,to take the difference, i want to map one list to ...
mehmet6parmak's user avatar
7 votes
4 answers
286 views

How to compare to list of date in C#? [duplicate]

I have two list of date. I have to compare both list and find missing date. My first list looks like this: 2015-07-21 2015-07-22 2015-07-23 2015-07-24 2015-07-25 2015-07-26 2015-07-27 My second list ...
Priya's user avatar
  • 591
6 votes
3 answers
15k views

Bigquery: STRUCT (*) syntax

How can I automatically apply STRUCT to all fields in a table without specifying them by name? Example that does not work: WITH data as ( SELECT 'Alex' as name, 14 as age, 'something else 1' ...
Ilja's user avatar
  • 1,023
6 votes
2 answers
3k views

Using Linq Except with two lists of int arrays

Is it possible to use except with two lists of int arrays, like so: List<int[]> a = new List<int[]>(){ new int[]{3,4,5}, new int[]{7,8,9}, new int[]{10,11,12} }; List<int[]> b = ...
Albertino's user avatar
6 votes
3 answers
14k views

Why does EXCEPT not work? Incorrect Syntax near the Word Except

SELECT SKU FROM PartProductSupplemental EXCEPT SELECT SKU FROM Inventory Why do I get this error: Incorrect Syntax near the Word Except I check on line and syntax is syntactically correct: ...
bizness's user avatar
  • 95
6 votes
1 answer
1k views

LINQ "Except" Operator

i have a list of event Ids that i want to be excluded from my select statement, but no sure how to implement this: this is what stores my list of event Ids List<int> ExcludedEvents; and this ...
kb.'s user avatar
  • 1,000
6 votes
0 answers
412 views

How does the "ThrowHelper" .Net Framework class help lessen the generated IL code?

I was looking at this and it its starting comments it says it exists because throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); generates ...
user14092802's user avatar
6 votes
1 answer
2k views

Tensorflow GPU memory error try-except not catching the error

I am trying to run a hyperparameter optimization (using spearmint) on a big network with lots of trainable variables. I am worried that when I try a network with the number of hidden units too large, ...
unknown_jy's user avatar
6 votes
1 answer
3k views

Laravel Collections - Using Except on multidimensional collection

Is there any method to remove properties from multidimensional collections? e.g I have public function getPossibleAnswersAttribute() { return collect([ [ 'option' => 'A', ...
owenmelbz's user avatar
  • 6,328
5 votes
3 answers
15k views

python try except yield combination

I use function f to create generator but sometimes it can raise error. I would like two things to happen for the main code The for loop in the main block continues after catching the error In the ...
nos's user avatar
  • 20.4k
5 votes
1 answer
10k views

Using EXCEPT clause in PostgreSQL

I am trying to use the EXCEPT clause to retrieve data from table. I want to get all the rows from table1 except the one's that exist in table2. As far I understand, the following would not work: ...
jsp's user avatar
  • 2,596
5 votes
2 answers
11k views

Python - How to print the message inside ValidationError

I would like to know how to print the string written when raising an exception. For example if I use raise ValidationError("RANDOM TEXT HERE"); How can I retreive "RANDOM TEXT HERE" from within ...
Rorchackh's user avatar
  • 2,153
5 votes
3 answers
5k views

django objects.get() does not find result

quick question. I run the following code with a try except statement (as it is possible that there is no entry in the database). And for some entries I run into the except block although there is an ...
user2601983's user avatar
5 votes
4 answers
3k views

Using IEnumerable.Except

I got 3 listViews 2 textbox and 2 buttons in WinForm. Program Description: The program adds numbers to the listview by typing in numbers in the textbox and clicking the add button Goal: I want to be ...
taji01's user avatar
  • 2,595
5 votes
4 answers
378 views

Keeping try block small when catching exceptions in generator

How can I keep the try block as small as possible when I have to catch an exception which can occur in a generator? A typical situation looks like this: for i in g(): process(i) If g() can raise ...
Alfe's user avatar
  • 58k
4 votes
3 answers
3k views

SQL UPDATE all rows, except some rows, in table with composite primary key

I'm struggling with a SQL statement. I want to update all rows except some, in a table with a composite primary key. This is what I do now: UPDATE Products SET Active = 0 _ UPDATE Products SET ...
Jon List's user avatar
  • 1,514
4 votes
3 answers
16k views

Python PyAutoGUI return "ImageNotFoundException", but "except" doesn't recognise it as an exception

With the previous version of pyautogui, when an image wasn't found the return was "None", so I used to handle it with except TypeError:. But since the update (version 0.9.41), it isn't working, as it'...
D. E. Scioli's user avatar
4 votes
3 answers
27k views

Try and Except (TypeError)

What I'm trying to do is create a menu-style start in my program that let's the user choose whether they want to validate a code or generate one. The code looks like this: choice = input("enter v for ...
AntsOfTheSky's user avatar
4 votes
2 answers
5k views

Syntax error, "except pygame.error"

I am a python and pygame noob, looked up a tutorial for loading sprites in to my game, and I'm getting syntax error for this this line of code except pygame.error, message: ^ ...
Fatnomen's user avatar
4 votes
3 answers
3k views

How to remove all elements of a FormArray but one specific index?

Is there any built-in functionality in Angular, so that I can say: remove all FormArray elements except at index 2 maybe something like 'RemoveRange" as known from other libs?
user avatar
4 votes
2 answers
1k views

List<T>.Except(List<T>) not working as expected

I have two lists of the same type. One list is a deserialized json object loaded from a file and casted to the correct type. The other is a list created of objects of the same type. When I do List2....
5SK5's user avatar
  • 169
4 votes
2 answers
614 views

Using EXCEPT where 1=0

I saw the following posted on a basic way to de-dup entries, without explanation of how it works. I see that it works, but I want to know the workings of how it works and the process in which it ...
Nick A's user avatar
  • 126
4 votes
4 answers
7k views

OOP / try except statements in __init__ of class

I want to control the input of the class Webpage. Meaning, I want to be sure that the webpage's link is appropriately provided, e.g. 'http://example.com'. class Webpage(object): def __init__(...
mikeel's user avatar
  • 43
4 votes
3 answers
1k views

Scope using except is not working Rails

I write Hi, but SO wouldn't let it, so I write longer sentence :) Hi by the way. It looks like my scope is not working. I wrote that scope: scope :ordered, ->(field, order) { except(:order)....
Bachet's user avatar
  • 321
4 votes
1 answer
12k views

SQL query operator minus is not working

(SELECT IDOperatore FROM operatore) MINUS (SELECT IDOperatore FROM commessaoperatore GROUP BY IDOperatore) This query is no working, even if I try to replace MINUS with EXCEPT. The singular query ...
vankraster's user avatar

1
2 3 4 5
13