Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Class and methods
#1
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)
Programs are like instructions or rules. Learning it gets us closer to a solution. Desired outcome. Computer talk.
Reply
#2
python packages, 538,397 of them here
Reply
#3
(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.
« We can solve any problem by introducing an extra level of indirection »
Reply
#4
Thanks. Just browsing through the threads.
Programs are like instructions or rules. Learning it gets us closer to a solution. Desired outcome. Computer talk.
Reply
#5
#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 ===
Programs are like instructions or rules. Learning it gets us closer to a solution. Desired outcome. Computer talk.
Reply
#6
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")
Reply
#7
Okay. I'll study harder.
Programs are like instructions or rules. Learning it gets us closer to a solution. Desired outcome. Computer talk.
Reply
#8
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
Programs are like instructions or rules. Learning it gets us closer to a solution. Desired outcome. Computer talk.
Reply
#9
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.
Reply
#10
(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
Programs are like instructions or rules. Learning it gets us closer to a solution. Desired outcome. Computer talk.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Class and methods Saida2024 2 265 May-13-2024, 04:04 AM
Last Post: deanhystad
  Class test : good way to split methods into several files paul18fr 4 579 Jan-30-2024, 11:46 AM
Last Post: Pedroski55
  [split] Class takes no arguments bily071 2 688 Oct-23-2023, 03:59 PM
Last Post: deanhystad
  Structuring a large class: privite vs public methods 6hearts 3 1,168 May-05-2023, 10:06 AM
Last Post: Gribouillis
  access share attributed among several class methods drSlump 0 1,093 Nov-18-2021, 03:02 PM
Last Post: drSlump
  a function common to methods of a class Skaperen 7 2,714 Oct-04-2021, 07:07 PM
Last Post: Skaperen
  Listing All Methods Of Associated With A Class JoeDainton123 3 2,415 May-10-2021, 01:46 AM
Last Post: deanhystad
  too many methods in class - redesign idea? Phaze90 3 2,563 Mar-05-2021, 09:01 PM
Last Post: deanhystad
  Special Methods in Class Nikhil 3 2,363 Mar-04-2021, 06:25 PM
Last Post: Nikhil
  cant able to make methods interact with each other in the class jagasrik 2 1,854 Sep-16-2020, 06:52 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020