[Redash] Standard library cannot be used in python function

I'm using python as a data source in Redash, and I'm a little addicted to it, so I'll leave it.

environment

Cannot use standard library in function

I wanted to use the datetime library imported at the beginning in the hoge function as shown below.

import datetime

def hoge():
    print(datetime.datetime.now())

hoge()

↓ An error occurred when Executed. (!?)

Error running query: <type 'exceptions.NameError'> global name 'datetime' is not defined

Solution

I imported it in the function and it worked.

def hoge():
    import datetime
    print(datetime.datetime.now())

hoge()
# -> [2020-02-12T09:59:05.617825] 2020-02-12 09:59:05.617767

Recommended Posts

[Redash] Standard library cannot be used in python function
Can be used in competition pros! Python standard library
[Memorandum] Japanese keys cannot be used in python string.Template.substitute
Operators ++,-cannot be used in python (difference from php)
Python standard input summary that can be used in competition pro
++ and-cannot be used for increment / decrement in python
Standard .py file used in Python trials (template)-2020
I made a familiar function that can be used in statistics with Python
Python note: When the pip command cannot be used
Japanese can be used with Python in Docker environment
Create a function in Python
Use callback function in Python
ntile (decile) function in python
[Python] Frequently used library code
Overriding library functions in Python
Transposed matrix in Python standard
Nonlinear function modeling in Python
Draw implicit function in python
Immediate function in python (lie)
How to debug the Python standard library in Visual Studio
Video cannot be loaded with Spyder in Python development environment
Implement R's power.prop.test function in python
Function argument type definition in python
8 Frequently Used Commands in Python Django
Included notation in Python function arguments
[Python] It seems that global variables cannot be referenced in Multiprocessing
Write AWS Lambda function in Python
[Python] Basic knowledge used in AtCoder
Make standard output non-blocking in Python
33 strings that should not be used as variable names in python
Windows10: Install MeCab library in python
Investigating what could be used as a Markdown parser in Python
Function synthesis and application in Python
New features in Python 3.9 (1)-Union operators can be used in dictionary types
Jupyter Notebook 6.0.2 cannot be installed in the Python 2.7 environment created in Anaconda
Python standard module that can be used on the command line
Modules cannot be imported in Python on EC2 run from AWS Lambda
I tried to put PyCharm in Ubuntu 16.04 LTS (PPA cannot be used)
[Python, Julia] 3D display in Jupyter-Mayavi library
Precautions when pickling a function in python
OR the List in Python (zip function)
[python] Frequently used techniques in machine learning
What is "mahjong" in the Python library? ??
Python modules with "-(hyphen)" cannot be removed
Tkinter could not be imported in Python
Python standard library: second half (Python learning memo ⑨)
Python standard library: First half (Python learning memo ⑧)
A solution to the problem that the Python version in Conda cannot be changed
python function ①
[Python] function
Let's look at a differential equation that cannot be solved normally in Python
How to install a Python library that can be used by pharmaceutical companies
Get all standard inputs used in paiza and competitive programming with int (python)
Correspondence memo when the direction key cannot be used on the python command line
python function ②
De-VBA Excel tool! Eliminate VBA tool with Python in environment where Python cannot be installed
How to use the C library in Python
Draw a graph of a quadratic function in Python
Project cannot be created with Python3.5 (Windows) + django1.7.1
Automatically register function arguments to argparse in Python
Functions that can be used in for statements