Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to combine import and from import in one statement?

Is there a way to combine import and from import in one statement?

Can:

from random import choice
import random

be combined into one statement?

like image 279
Sam Avatar asked Oct 17 '25 17:10

Sam


1 Answers

No, they can't.

See the import statement grammar:

import_stmt     ::=  "import" module ["as" name] ( "," module ["as" name] )*
                     | "from" relative_module "import" identifier ["as" name]
                     ( "," identifier ["as" name] )*
                     | "from" relative_module "import" "(" identifier ["as" name]
                     ( "," identifier ["as" name] )* [","] ")"
                     | "from" module "import" "*"

The import module and from relative_module import forms are two entirely separate forms in the grammar.

like image 99
Martijn Pieters Avatar answered Oct 20 '25 06:10

Martijn Pieters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!