I just started working with Python and ran into an annoyance. Is there
a way to avoid having to use the "from xxx import yyy" syntax from
files in the same directory? I'm sure it's been asked a million times,
but I can't seem to find the answer.
For example, I have two classes stored in separate files as such.
File: one.py
========
class One:
def methodA(self):
print "class One"
def methodB(self):
print "class One"
File two.py
========
from one import One
class Two(One):
def methodA(self):
print "class Two"
if __name__ == "__main__":
x = Two()
x.methodA()
x.methodB()
When I run the Two.py file, I get the expected output but I'd like to
eliminate the from line in two.py. 9 2019 dh****@gmail.co m wrote:
I just started working with Python and ran into an annoyance. Is there
a way to avoid having to use the "from xxx import yyy" syntax from
files in the same directory? I'm sure it's been asked a million times,
but I can't seem to find the answer.
Probably none that are better.
1:
import one
class Two(one.One)
2:
put both classes in the same file.
It's just the way it is. Why worry about it?
For example, I have two classes stored in separate files as such.
File: one.py
========
class One:
def methodA(self):
print "class One"
def methodB(self):
print "class One"
File two.py
========
from one import One
class Two(One):
def methodA(self):
print "class Two"
if __name__ == "__main__":
x = Two()
x.methodA()
x.methodB()
When I run the Two.py file, I get the expected output but I'd like to
eliminate the from line in two.py.
--
hilsen/regards Max M, Denmark http://www.mxm.dk/
IT's Mad Science
Phone: +45 66 11 84 94
Mobile: +45 29 93 42 96 dh****@gmail.co m:
Is there
a way to avoid having to use the "from xxx import yyy" syntax from
files in the same directory?
You can just use:
import xxx
and then:
class Two(xxx.One):
...
If you don't want to use the import line, you have to put the two
classes into the same module.
Bye,
bearophile
It's just the way it is. Why worry about it?
Wasn't so much a worry, just trying to figure out how to think the
python way.
Max M wrote:
dh****@gmail.co m wrote:
I just started working with Python and ran into an annoyance. Is there
a way to avoid having to use the "from xxx import yyy" syntax from
files in the same directory? I'm sure it's been asked a million times,
but I can't seem to find the answer.
Probably none that are better.
1:
import one
class Two(one.One)
2:
put both classes in the same file.
It's just the way it is. Why worry about it?
For example, I have two classes stored in separate files as such.
File: one.py
========
class One:
def methodA(self):
print "class One"
def methodB(self):
print "class One"
File two.py
========
from one import One
class Two(One):
def methodA(self):
print "class Two"
if __name__ == "__main__":
x = Two()
x.methodA()
x.methodB()
When I run the Two.py file, I get the expected output but I'd like to
eliminate the from line in two.py.
--
hilsen/regards Max M, Denmark
http://www.mxm.dk/
IT's Mad Science
Phone: +45 66 11 84 94
Mobile: +45 29 93 42 96
On 9 Aug 2006 12:35:48 -0700
"dh****@gmail.c om" <dh****@gmail.c omwrote:
>
It's just the way it is. Why worry about it?
Wasn't so much a worry, just trying to figure out how to think the
python way.
Seems like you're thinking the Java way... if you don't want to do it,
put both classes in the same file.
--
Pedro Werneck
At Wednesday 9/8/2006 16:24, dh****@gmail.co m wrote:
>I just started working with Python and ran into an annoyance. Is there a way to avoid having to use the "from xxx import yyy" syntax from files in the same directory? I'm sure it's been asked a million times, but I can't seem to find the answer. [...] When I run the Two.py file, I get the expected output but I'd like to eliminate the from line in two.py.
Embody the Zen of Python: http://www.python.org/dev/peps/pep-0020/
Gabriel Genellina
Softlab SRL
_______________ _______________ _______________ _____
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! http://www.yahoo.com.ar/respuestas
Yes, I have been ruined for the last 5 years with Java and C#. Perl was
my only salvation, but now I can't read the programs I wrote.
Pedro Werneck wrote:
On 9 Aug 2006 12:35:48 -0700
"dh****@gmail.c om" <dh****@gmail.c omwrote:
It's just the way it is. Why worry about it?
Wasn't so much a worry, just trying to figure out how to think the
python way.
Seems like you're thinking the Java way... if you don't want to do it,
put both classes in the same file.
--
Pedro Werneck
dh****@gmail.co m wrote:
Yes, I have been ruined for the last 5 years with Java and C#. Perl was
my only salvation, but now I can't read the programs I wrote.
ROFL! That's got to be a contender for Quote of the week.
Perhaps __init__.py has what you're looking for?
THN dh****@gmail.co m wrote:
I just started working with Python and ran into an annoyance. Is there
a way to avoid having to use the "from xxx import yyy" syntax from
files in the same directory? I'm sure it's been asked a million times,
but I can't seem to find the answer.
For example, I have two classes stored in separate files as such.
File: one.py
========
class One:
def methodA(self):
print "class One"
def methodB(self):
print "class One"
File two.py
========
from one import One
class Two(One):
def methodA(self):
print "class Two"
if __name__ == "__main__":
x = Two()
x.methodA()
x.methodB()
When I run the Two.py file, I get the expected output but I'd like to
eliminate the from line in two.py.
Pedro Werneck <pe***********@ terra.com.brwro te:
>"dh****@gmail. com" <dh****@gmail.c omwrote:
>Wasn't so much a worry, just trying to figure out how to think the python way.
Seems like you're thinking the Java way... if you don't want to do it, put both classes in the same file.
OP: think of a .py file as being more akin to Java package than a .java
file. Don't worry about the resulting files getting too large -- Python
is a lot more compact than Java.
--
\S -- si***@chiark.gr eenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Phil Powell |
last post by:
Where can I find an online PHP form validator script library to use? I
have tried hacking the one here at work for weeks now and it's getting
more and more impossible to customize, especially now with form
elements that turn out to be arrays that have to be compared with one
another!
I have one form element, languages, a checkbox group. Beside each
checkbox is a dropdown, proficiency (which will become proficiency
alongside languages)....
|
by: TheLetti |
last post by:
Hy!
I've just downloaded the latest Java 2 SDK (j2sdk1.4.2_01).
For my surprise in this version the servlet-classes are not integrated
(e.g. the class javax.servlet).
So I found all the servlet-classes I needed on the
java.sun.com-Homepage and downloaded the javax.servlet-Package.
(Maybe this file-description may help you understanding my problem:
|
by: Aguilar, James |
last post by:
I know that one can define an essentially unlimited number of classes in a
file. And one can declare just as many in a header file. However, the
question I have is, should I?
Suppose that, to use the common example, I have a situation where I am
implementing many types of Shapes. My current way of thinking is, well,
since they are all the same type, let's just put them all in the same file.
The include file would be "shapes.h" and it...
|
by: Javi |
last post by:
I have some doubts about what is the best method to distribute classes in .cpp and .h files:
- Should I use a file per class? or should I group similar classes in one file?
- Is it good to put a lot of class declarations in the same .h, and their definitions in different .cpps?
- And, to the contrary, many definitions in one cpp and declarations in different .h?
- How to deal with precompiled headers? is it ok to include all headers in the...
|
by: joye |
last post by:
Hello,
My question is how to use C# to call the existing libraries containing
unmanaged C++ classes directly, but not use C# or managed C++ wrappers
unmanaged C++ classes?
Does anyone know how to do that?
Thanks.
Tsung-Yu
| |
by: Alex Maghen |
last post by:
I love that I can create ASPX and ASCX files with CS code embedded or in code-behind files and ASP.NET will auto-compile it all for me. I *like* it that way
Is there ANY way to have classes defined in .cs files somewhere and have them accessed by my ASPX, ASCX, and Code-Behind files WITHOUT having to manually compile them first???
|
by: ptass |
last post by:
Hi
In asp.net 2.0 an aspx files .cs file is a partial class and all works fine,
however,
I thought I’d be able to create another class file, call it a partial class
and have
that compile and load as a 3rd partial class. This would be handy so i can
generate
standard code into one of the partial classes, while having my custom code
untouched
|
by: Sylvia A. |
last post by:
How can I define global classes in web application ?
Classes can be set to session variables ?
Thanks
|
by: Swapnil Kale |
last post by:
Hi,
I'm working on a Migration project (Forte to JAVA).
The forte client had a C++ dll which used to call one more FORTE dll
for a complex database calculations.
Now all the forte code has been migrated to JAVA except this piece of
code where C++ dll calls Forte DLL.
|
by: Nathan Sokalski |
last post by:
I have several CustomControls that I have written for my project. However,
when I try to compile I recieve the following warning & errors:
Warning 32 Could not resolve this reference. Could not locate the assembly
"nathansokalski_com_test, Version=1.0.0.0, Culture=neutral,
processorArchitecture=MSIL". Check to make sure the assembly exists on disk.
If this reference is required by your code, you may get compilation errors....
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |