Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6112325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:43:58+00:00 2026-05-23T14:43:58+00:00

I am from Java background. I am going through the official Python tutorials but

  • 0

I am from Java background. I am going through the official Python tutorials but can’t seem to find the information in relation to Python source file names and classes.

In Java, file name is the same as main class name plus the .java extension. In Python what’s the case? In the examples of official tutorials, they are writing multiple classes and there’s no mention of the file name. I am kind of lost.

I have a file name called test_pie.py. The content is-

class ListTest:

    list1 = [2, 'a', 'ab', 'c', 'aa', 0]

    list2 = ['b', list1[-2:-5]] 

    def PrintList(self):
        print list1
        print list2

For list1 and list2: I get-

Undefined variable: list1
list Found at: test_pie

Undefined variable: list2
list Found at: test_pie

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:43:58+00:00Added an answer on May 23, 2026 at 2:43 pm

    There’s a file. Period. Whatever is contained in it is of no interest for imports, and the file name or location doesn’t have any effect on the contained code (generally – it is accessible during execution, so some metaprogramming makes use of it but should be agnostic w.r.t. the actual value).

    The contents of a file are not restricted to a single class, and few people impose such a restriction onto themselves. Python isn’t exclusively an OO language, you can and should have free functions whenever it’s sensible, and modules are seen one level above classes in code organizations – if several classes are closely related, they should propably go in one module.

    Your example code/problem is unrelated to this, it’s a matter of scoping inside a given file. Classes do have their own scope, but you can’t and shouldn’t be using the class variables of the containing class in methods like this (directly) – it would make the code oblivious to a new value set in a subclass. Instead, you either use class methods (by the way, you should propably read http://dirtsimple.org/2004/12/python-is-not-java.html) or make use of the fact that instances inherit all members of the class and just prefix it with self..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I come from Java Background and so used to Debugging using Eclipse but have
I come from a java background. But I would like a cross-platform perspective on
I'm new to Python and come from a Java background. I'd like to know
I'm trying to structure my app in Python. Coming back from C#/Java background, I
Static variable gotcha in php I am from Java background and have switched to
Coming from a java background, one of the things I am used to is
Coming from a Java background, this is the way I'm thinking: The server provides
Coming from a Java background, this is the way I'm thinking: The server provides
I come from a Java background, where packages are used, not namespaces. I'm used
I come from a Java background and with any servlets-based technology, it's trivial to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.