Python Forum
now i wish Python had a way to add commands
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
now i wish Python had a way to add commands
#5
I think this comes pretty close to what you're asking. First, put this code in a file callednewcommands. Then start the interactive interpreter with this:PYTHONSTARTUP=newcommands python3. Then you can typec.dieorc.lsorc.pwd. Try it Smile and then add all the commands you like.
import os
class Commands :
	@property
	def ls (self) :
		directory_list = os.listdir ()
		for filename in directory_list :
			print (filename)

	@property
	def pwd (self) :
		print (os.getcwd())

	@property
	def die (self) :
		exit ()

c = Commands ()
'''
	c.ls
	c.pwd
	c.die
'''
Reply


Messages In This Thread
RE: now i wish Python had a way to add commands - by BashBedlam - Dec-27-2021, 01:33 AM

Forum Jump:

User Panel Messages

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