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
-1
votes
1 answer

How to correct SQL Syntax Error for WITH clause?

Dealing with a syntax error (Encountered: SELECT, Expected: CROSS, FROM, GROUP,...) when trying to SELECT t1.*. The middle of my code runs without error (table t1) but when trying to select table t1, I get an error. The code: with test as ( …
gfgd
  • 17
  • 2
-1
votes
1 answer

How to implement a LEFT OUTER JOIN CLAUSE after WITH AS?

Currently trying to figure out how to implement a SQL LEFT OUTER JOIN while using the SQL WITH AS clause. My code breaks down into 3 SELECT statements while using the same table, then using LEFT OUTER JOIN to merge another table on the id. I need 3…
gfgd
  • 17
  • 2
-1
votes
1 answer

How to specify count() as limit to recursive iterations from a CTE?

I'm trying to limit the amount of recursive iterations from a common table expression using join, but it loops infinitely regardless. What am I doing wrong? I don't want a fixed iteration limit, but limit according to count(*) of data table…
-1
votes
1 answer

VBA Loop For Each Workbook and Sheets if avail. loop doesn't activate second sheet

Sub Invoice_Collation() Dim MyPath As String, FilesInPath As String Dim MyFiles() As String, Fnum As Long Dim mybook As Workbook Dim CalcMode As Long Dim sh As Worksheet Dim ErrorYes As Boolean Dim wb As Workbook Dim…
Iniyavan
  • 3
  • 2
-1
votes
2 answers

How to extract the full path from a file while using the "with" statement?

I'm trying, just for fun, to understand if I can extract the full path of my file while using the with statement (python 3.8) I have this simple code: with open('tmp.txt', 'r') as file: print(os.path.basename(file)) But I keep getting an error…
-1
votes
1 answer

Python:: Read file includes strings, floats and integers

I am trying to read a file includes string, floats and integers in a form of matrix, I tried the following code: import numpy as np with open('data.dat', 'r') as f: input_data = f.readlines() for p in input_data: pizza_details =…
msci
  • 89
  • 6
-1
votes
1 answer

with statement python __enter__ attribute error

This : def add_to_excel(list_to_save, file_to_save_in): my_file = dir_path + '\\' + file_to_save_in with openpyxl.load_workbook(filename=my_file) as links_excel: sheet = links_excel['Sheet1'] for i in list_to_save: sheet.append(i) …
Tantalus
  • 29
  • 5
-1
votes
2 answers

pycharm ide gives syntax error with python 3.10 but code is working fine

hi I just installed windows 11 and python 3.10 and pycharm 2021.2.2 now when I use python 3.10 in pycharm and use some new features in python 3.10 i get some highlight in my code but the code is working fine here is what I'm experiencing : i really…
HadiH2o
  • 302
  • 2
  • 18
-1
votes
2 answers

Trouble getting function to run once to alert across all worksheets

I am trying to run a Range code that If any value in a range is <1, it will alert the user. After trying multiple codes, this is the only one that doesn't run an error code. HOWEVER, it runs each page individually and is giving an incorrect answer.…
-1
votes
1 answer

How to Replace with()

I've been reading up on with() and trying to figure out how to rewrite this piece of code. _$createRootItemAreas: function() { var areaSize = 50; var sides = { y2: 0, x2: 0, y1: 'y2', x1: 'x2' }; for( side in sides ) { …
leoplaw
  • 53
  • 7
-1
votes
2 answers

Python, check if called within 'with' statement

I am implementing my custom open() function (let's call it myOpen()). The task is, that I would like to be able to use this function also with with statement (with myOpen(...) as myFile:). As far as I know, open() must return file object (TextIO or…
wynxel
  • 31
  • 2
-1
votes
3 answers

How do i calculate percentage out of sum in mysql?

Ive got this simple table browser pageviews safari 7.1875 ie 1.935 firefix 1.3445 safari 2.03 Im trying to calculate the percentage of the page views out of the total (in millions) for each browser. with total as ( select…
lennyb
  • 17
  • 3
-1
votes
1 answer

Oracle Top 5 Problems of Top 5 Sites

Hi all I'm new to this board, before I always viewed anonymously but now I have a specific Problem I cannot find the answer. I have two statements which do it individually very good Statement 1: Select Sites with most Problems WITH ordered_query…
Ulrich C.
  • 1
  • 1
-1
votes
1 answer

How to pass Sys.argv[n] to a function from inside if "__name__" == "__main__"

Hi guys I'm trying to write a code that scrapes websites and get the links from the websites. Now I'm trying to implement that a user will give the script a link_list.txt that the script will iterate over. However, I'm not successful with my…
-1
votes
1 answer

VBA script 'object variable or with block variable not set' on find function

I am running through about 500 iterations of the same type of procedure and I run into this error on the 227th iteration. I'm not sure why it works for all of the items before hand or why it stops working here. The generalized code looks like…
rawmud
  • 70
  • 9