Questions tagged [with-statement]

A number of languages have With statements. The Python with statement creates a new context, with associated context manager. When the context (a code block) is exited again, the context manager is notified. Please use "common-table-expression" for the SQL WITH construction.

A number of languages have With statements. Python's with statement creates a runtime context, defined by a . As the code block under the with statement is entered, a __enter__ hook is called on the context manager, and as it is exited (by any means, including exceptions and return statements), the __exit__ hook is called.

Python provides several standard context managers. File objects, for example, can be opened as a context manager, and on exit the file is automatically closed.

Context managers were defined in PEP 343.

Please use for the SQL WITH statement

1119 questions
0
votes
1 answer

Problems doing update with Join on SQL Server 2012

I am not very experienced with SQL but I have put together a query that I though should update two prices in one table (to add on 20% tax) using the description in another table by joining the tables, here is my problem code:- UPDATE IT_PRICE SET…
0
votes
2 answers

Using two With statements

First, I was haveing combobox1 fill combobox2 during the onselect. I started the long way see below. procedure TFGetZoneDept.ComboBox1Select(Sender: TObject); begin Combobox2.Clear; with Combobox1 do begin if text = '3' then …
Glen Morse
  • 2,437
  • 8
  • 51
  • 102
0
votes
3 answers

Equivalent of VBA With statement in Java

I am currently making my method call in the following way: InstrumentsInfo instrumentsInfo = new InstrumentsInfo(); String shortInstruName = "EURUSD" TrackInstruments trackInstruments = new…
jule64
  • 487
  • 1
  • 6
  • 19
0
votes
1 answer

Ruby on Rails with_option cannot call class method

I have a problem calling class method from the with_option block with validations: Model: class Model < ActiveRecord::Base attr_accessible :field with_options :if => "" do |step| ... bunch of validations …
Dmitri
  • 2,451
  • 6
  • 35
  • 55
0
votes
2 answers

Combining Threading with the "with" Keyword

When I run the following program: import threading class foo(threading.Thread): def __init__(self): threading.Thread.__init__(self) def __enter__(self): print "Enter" def __exit__(self, type, value, traceback): …
Strill
  • 228
  • 3
  • 10
0
votes
2 answers

What does this function do and How to rewrite without the 'with' statement - Javascript

Javascript: function ValidDate(y, m, d) { // m = 0..11 ; y m d integers, y!=0 with (new Date(y, m, d)) return (getMonth()==m && getDate()==d); /* was y, m */ }
Joshua Fricke
  • 381
  • 3
  • 14
0
votes
2 answers

Setting fields on and object referenced by the 'with' statement

In JavaScript, I simulate classes like this: function MyClass() {} // Constructor MyClass.prototype.myField = "foo"; I thought I'd make the code more readable and save keystrokes by using the with keyword: function MyClass() {} //…
Jack M
  • 4,769
  • 6
  • 43
  • 67
0
votes
1 answer

SQL Server WITH very slow

I am using SQL Server 2008 and am trying to run: WITH results (Row, code, p_name, phone, intake_date, shipped_status, shipped_date, event_status, intake_status, slsperson, referral_source, dr ) AS ( SELECT ROW_NUMBER() OVER (ORDER BY…
Mike
  • 1,718
  • 3
  • 30
  • 58
0
votes
1 answer

Python with statement

I'm reading PEP 343 and trying to make some examples. But it's not really clear to me now. Especially because I have an error: >>> def f(): ... return 'f' ... >>> with f(): # or as f ... print f() # or f ... Traceback (most recent call…
I159
  • 29,741
  • 31
  • 97
  • 132
0
votes
1 answer

Oracle: WITH statement performing slowly

Recently I have been trying to incorperate more WITH statements into my Oracle SQL in order to create cleaner, more efficient code. However, I continue to feel like it is actually less efficient, but only under certain conditions, which is…
Phillip
  • 447
  • 1
  • 4
  • 12
-1
votes
1 answer

How can I use a third-party context manager to run a custom-class's method?

In python, I'd like to use a with-statement context manager when using a particular third-party package because their context manager will handle clean-up for me in a best-practice way. Right now I have (say): class MyClass(object): def…
jtlz2
  • 7,700
  • 9
  • 64
  • 114
-1
votes
5 answers

How to write a specific portion in text file using file handling in python?

I am working on a project and want to print multiple lines in a text file. This is the method I used for this purpose. def story_part(file_path,initial_index,final_index): line_number = list(range((initial_index -1) ,final_index )) mylines =…
-1
votes
1 answer

Upload Parquet file to S3 Subfolders

I have attached the code as picture, please find the attachmentI have shared the code as picture, please find the attachment I have 2 folders, each folder will have 1 parquet zip file. Example: Folder-A xxx_timestamp.Parquet.zip file Folder-B…
-1
votes
2 answers

Replace or update table while using a with clause

I have a currency converter table where I'm missing dates on weekends. Using this query solves this by adding Fridays value to the following Saturday and Sunday. I've created this query that returns the table I would like to be my new…
daffy_daf
  • 1
  • 1
-1
votes
1 answer

What would cause the inner contents of a `with` statement to not execute?

When I run the following code, no error messages are printed, and it seems to fail silently. I expected the string "BLAH" to be printed to the console. from contextlib import redirect_stdout import io # the initialism `io` represents `INPUT OUTPUT…
Toothpick Anemone
  • 4,290
  • 2
  • 20
  • 42