Skip to main content

All Questions

Tagged with
0 votes
0 answers
21 views

Optimizing nested list-based storage format for defining curly brackets scopes

I have made my own programming language in python, and as of right now, its using a system that, whenever detects a {, it makes a list in front of it, somewhat like this: tokens = ['IF', 'a', '>', '...
Silicon's user avatar
2 votes
1 answer
83 views

Typing List not defined when running code with exec from a function

Can somebody help me understand why the following code fails? def foo(code): exec(code) if __name__ == "__main__": code = R""" from typing import List class Test: ...
Dano's user avatar
  • 21
0 votes
0 answers
32 views

A local variable seemingly breaking scope in Django [duplicate]

I have introduced this function in a file storage.py that is imported from models.py: def uuid_file_name(kind): def file_name(instance, filename): h = str(uuid.uuid4()) basename, ...
Amadan's user avatar
  • 197k
0 votes
0 answers
27 views

Why is my socket losing its type when passed into a function? [duplicate]

I receive the error: [WinError 10038] An operation was attempted on something that is not a socket def main(): test_sock = connToDevice("TEST") resetRobot(test_sock) def ...
Sam S's user avatar
  • 1
0 votes
2 answers
47 views

NameError when accessing variable returned from function (out of order?)

Per the code below, I'm getting this error: NameError: name 'leap_status' is not defined The def days_in_month() is looking for the status of leap_status which should be defined already but, for ...
J W's user avatar
  • 5
0 votes
1 answer
59 views

Positional arguments in nested functions

This question relates to this video: https://www.youtube.com/watch?v=jXugs4B3lwU The piece I'm missing is somewhat simpler than the concept the video is covering overall. In the example code below: ...
Chris's user avatar
  • 424
-1 votes
2 answers
78 views

I don't know how to make my code work correctly [closed]

I was practicing and I tried defining mathematical functions and other stuff, but then I got a bunch of errors and I ended up not having an error but the result was wrong. This is the code as of ...
MistyKing's user avatar
0 votes
0 answers
38 views

Variable visibility in python [duplicate]

Maybe a stupid question but I'm new to python. The following code throws an error: deck = [10, 2, 5, 8, 2, 7] deck_idx = 0 def deal(): card = deck[deck_idx] deck_idx += 1 return card print(...
Disti's user avatar
  • 1,484
0 votes
1 answer
35 views

why print(num) print '0'? num is global variable and I changed num to '6' in local function [duplicate]

When I compiled this code, I expected print(num) to print 6. The reason behind my expectation is that, firstly, the variable num is global. Thus, in the first line, num was reset to 0. Additionally, ...
김김김's user avatar
0 votes
1 answer
42 views

Use one correlated value from one Locust call in anoher (within same class)

I have the following working code: import json import requests import os import pandas as pd import random from locust import task, events from locust.contrib.fasthttp import FastHttpUser from azure....
Magnus Jensen's user avatar
0 votes
0 answers
19 views

Ipython: Slide a slider --> change text in a pdf

In the self-contained IPython/Jupyter code below, you drag a slider and the text in the pdf should change -- the pdf text should be regenerated when you release the mouse button. I see the slider. I ...
dnh37's user avatar
  • 463
0 votes
0 answers
41 views

Preserving DataFrame Modifications Across Options in a Streamlit Application

I have a Streamlit application called PredictaApp that allows users to upload a CSV file and perform various data analysis and preprocessing tasks on the uploaded dataset. One of the tasks is imputing ...
nafiz's user avatar
  • 1
0 votes
0 answers
38 views

Why is my function overwriting global variable values that are passed to it? [duplicate]

My understanding of variable scope in Python was that if you pass a global variable into a function, the global variable's value will not be changed by any operations done on it within the scope of ...
David Bluhm's user avatar
1 vote
0 answers
40 views

Local vs NonLocal Scope Python [duplicate]

I am trying to understand scopes in Python and am confused in the examples below (I am using Python 3.12.2) - 1. a = 10 def myfunc(): a = 2 print(a) print(a) myfunc() This gives the output -...
Aditi Garg's user avatar
-1 votes
1 answer
3k views

UnboundLocalError: cannot access local variable 'currentPlayer' where it is not associated with a value [duplicate]

I do not understand this error. 'currentPlayer' is declared and defined on line 13, which exists globally. Why is it unbound in my ToggleTurn() method? The error: Traceback (most recent call last): ...
Loganox's user avatar

15 30 50 per page
1
2 3 4 5
113