Issue defining global variables within functions
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, python
- Lĩnh vực
- compilers
Hướng nghiên cứu
No repository files or tests are named. Start by reproducing the two global-variable examples and inspecting the JavaScript generated for each, then trace the compiler behavior for Python global assignments and the globals() form. Done means either supporting the requested behavior with regression coverage or clearly documenting the supported workaround.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Hi! It's me again =]
I'm having an issue in my pyp5js project releated to not being able to create new global variables from inside a function. For example, the following pure Python code works:
def foo():
global x
x = 30
print(x)
foo()
>>> 30
But if an equivalent version to be browser, such as the following example, doesn't:
def foo():
global my_var
my_var = 10
console.log(my_var)
foo()
The error I get from the browser console is: ReferenceError: assignment to undeclared variable my_var at line 3. But, if I declare the global variable my_var outside the foo function, it works and prints "10" in the console:
my_var = None
def foo():
global my_var
my_var = 10
console.log(my_var)
foo()
Studying transcrypt's docs, I got to this page about the use of globals function and then I tried the following example, which didn't work either:
# __pragma__ ('xglobs')
def foo():
globals () ["my_var"] = 10
console.log("inside function", my_var)
foo()
console.log("outside function", my_var)
This one raises a ReferenceError: my_var is not defined at line 3 as well.
So, I'd like to know if is there'a way to respect regular Python's usage of global or, given the restrictions of compiling the code to JS, to use global variables should I have to declare them at the beginning of the module, before assigning values?
- Ngôn ngữ chính
- Python
- Star
- 2.9k
- Fork
- 218
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của TranscryptOrg/Transcrypt
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
TranscryptOrg/Transcrypt#913 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
TranscryptOrg/Transcrypt#911 · 2 bình luận ·
-
IS: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
TranscryptOrg/Transcrypt#908 ·
-
SUB: documentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
TranscryptOrg/Transcrypt#656 · 7 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 76/100
TranscryptOrg/Transcrypt#914 ·
Tất cả issue của TranscryptOrg/Transcrypt
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
zostera/django-bootstrap4#894 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
use-agent-os/agent-os#3276 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
NousResearch/hermes-agent#117848 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
zilliztech/memsearch#759 ·