Python Forum

Full Version: [split] Class and methods
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
This is my first post. I'm new to Python programming. I usually go on Windows, Linux, C#, and Java programming on coding. I wanted to take up Python because I thought it looked good. I would like to know few things about the structure of programming in Python. First I'll put the title on...

Java has java packages to work on. I'd like to know what about Python programming. Same idea?
#saving a file or loading a file
import arcpy
featureclass = "C:/data/county.gdb/hospital"
field = "Zip"

valueList = []
rows = arcpy.da.SearchCursor(featureclass, [field])
for row in rows:
    valueList.append(row[0])

uniqueSet = set(valueList)
uniqueList = list(uniqueSet)
uniqueList.sort()

print(uniqueList)
python packages, 538,397 of them here
(May-12-2024, 02:25 AM)ebn852_pan Wrote: [ -> ]Java has java packages to work on. I'd like to know what about Python programming. Same idea?
Python has Python modules also called packages if they have more than one file. If you install packages from Pypi as suggested by @Larz60+, install well-known packages because everybody can create a Pypi package, so take the time to look inside the package before installing.
Thanks. Just browsing through the threads.
#bike.py
print("Welcome to the Bike Shop")

# constructor function    
def __init__(self, name = ""):
    self.name = name
        
a = input()
print("We sell these types of Bikes for all ages")

#create class Bike
class Bike:
    name = " "
    gear = " "
    
#create object of the class
bike1 = Bike()
bike2 = Bike()
bike3 = Bike()
bike4 = Bike()
#access class attributes and using objects
bike1.name = "Mountain Bike"
bike2.name = "Ten speed bike"
bike3.name = "Racing Bike"
bike4.name = "Regular Bike"

#access gear property
bike1.gear = 11
bike2.gear = 10
bike1.name = "Mountain Bike"
bike2.name = "Ten speed Bike"
bike3.name = "Racing Bike"
bike4.name = "Regular Bike"

print(f"name: {bike1.name}, gear:{bike1.gear}")
print(f"name: {bike2.name}, gear:{bike2.gear}")
print(f"name: {bike3.name}")
print(f"name: {bike4.name}")
print()
print("Let any one of our sales staff know if you need assistance.")
Here's a program I came up with. bike.py. Does Python programming work like this? I could use this class file bike.py in another class or object of a class in another folder or website? Or use that part of bike.py file. Thanks.
Quote:Try programiz.pro
Welcome to the Bike Shop
Thank you.
We sell these types of Bikes for all ages
name: Mountain Bike, gear:11
name: Ten speed Bike, gear:10
name: Racing Bike
name: Regular Bike

Let any one of our sales staff know if you need assistance.

=== Code Execution Successful ===
I'd do things differently.
class Bike():
    def __init__(self, style="Regular", gears=1):
        self.style = style
        self.gears = gears

    def __str__(self):
        return f"{self.style} bike, gears = {self.gears}"


bikes = [
    Bike("Mountain", 11),
    Bike("Road", 10),
    Bike("Racing"),
    Bike()
]

print(*bikes, sep="\n")
Okay. I'll study harder.
Hello again.
I'm using a Bulletin Board Codes for a website. Using these codes.
İmage

I want to know if it's possible from python interpreter like python programiz.com and send it to that or someone's URL web page just from that codes or class files. Or modules.
I don't know whether to apologize or thank you. But I want to keep this forum professional.
URL looks something like this...

That means they'll know my ip address, localhost name, and network I'm on. Picture from that file. Placing the picture in their database.

https://wnhpc.com/wnhpcphoto1732-s.jpg
Welcome! In Python, Its really a powerful programming language. I'm also new, using modules and packages to organize code, similar to Java. Your example looks good. Python’s straightforward syntax makes tasks easy.
(May-20-2024, 06:46 PM)LauraB Wrote: [ -> ]Welcome! In Python, Its really a powerful programming language. I'm also new, using modules and packages to organize code, similar to Java. Your example looks good. Python’s straightforward syntax makes tasks easy.
Thanks. And you're a python developer? I just started this month. The program looks like basic programing of which I learned well in 1987. But now I am on Java and hopefully to pick up points on Python programming. Websites. Shocked Undecided Shy Angel
Pages: 1 2