Is there any way I can execute a block of code in a loop, like so: [ some code goes here ] Where the delimiters are "[" and "]", and also allowing for nested blocks, i.e.: [the user can create another loop[]] I am creating a parser for a language that implements such semantics, and it reads the code one byte/character at a time since the commands are all single characters (which is fairly important), and I am currently stuck in this loop thing. Any help (in Python, possibly) is appreciated!

Member Avatar
Member Avatar
+0 forum 2

I've been looking for a way to parse a simple XML-like language for use as a type of data storage. I've been through stuff like JSON, XML, etc but I don't want to use them because they are quite slow. I just need a simple way to parse this: [stuff] [key1]data[/key1] [key2]data[/key2] [/stuff] And make/map it into a dictionary, like this: {"stuff":{"key1":"data", "key2":"data"}} I've made myself a generator which will process a dictionary according to the syntax rules: def generate_di(self, item) assert type(item) is dict for key in item: if type(item[key]) is dict: self.puts(self.strtag % key) # means we are …

Member Avatar
Member Avatar
+0 forum 7

So I have this piece of code in a socket server: def process(self, request, client_address): input_file = request.makefile("rb", 0) output = request.makefile('wb', 0) remote_input = input_file.readline().strip() + b"\n" self.log(remote_input) self.proc.stdin.write(remote_input) self.proc.stdin.flush() self.proc.stdout.flush() while True: line = self.proc.stdout.readline() line = line.decode() if line: line = bytes(line.rstrip() + "\n", 'utf-8') output.write(line) else: break Where `self.proc` is a subprocess with the following setup: self.proc = subprocess.Popen( ["/bin/bash"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE) It seems to work fine for the first time, then breaks afterwards- for example, Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. hello /bin/bash: line 1: hello: command not found this doesn't …

Member Avatar
Member Avatar
+0 forum 1

So I have a code that prints out the `sys.argv` when the program is ran. How can I parse $ python ./arch.py install * to show `["./arch.py","install","*"]` Instead of `["./arch.py","install",#other files in directory]`?

Member Avatar
Member Avatar
+0 forum 1

How do you start a SSH server on localhost through executing a shell script? If so, is there any way to restrict the commands performed or use another shell script as it's default console (i.e. Instead of Terminal.app it uses X11)?

Member Avatar
Member Avatar
+0 forum 2

For some reason , my code keeps returning a false reply even if the string is in the file. Here's my code: def check(self): self = str(self) if self in config_file: print ('Account exists') if self not in config_file: print ('Account doesn't exist')

Member Avatar
Member Avatar
+0 forum 2

How could I make the return command in Python return a list AS a list, and not as a 'programmer' list? For example, for line in list: return (line) But for some reason it only returns the first element in the list, for example: myList = ['1','2','a','b'] for line in myList: return (line) >>> 1 >>> And that's all I get. Any form of help is appreciated!

Member Avatar
Member Avatar
+0 forum 6

How do you make Python accept multiple strings and break them down in an input? For example, main = input ('> ') if main == ('ECHO',some_words): print (some_words) But everytime I do that, the some_words string wouldn't be defined. Error Message: Traceback (most recent call last): File "<pyshell#7>", line 1, in <module> if main == ('ECHO',some_words): NameError: name 'some_words' is not defined Can someone please teach me how?

Member Avatar
Member Avatar
+0 forum 6

Can someone give a code snippet on how to 'chat' using the XMLRPC library in Python? Here's my server code: from xmlrpc.server import SimpleXMLRPCServer from xmlrpc.server import SimpleXMLRPCRequestHandler import os from os import access, path PATH = 'chatlog.$' class RequestHandler(SimpleXMLRPCRequestHandler): rpc_paths = ('/RPC2',) server = SimpleXMLRPCServer(("localhost", 8000), requestHandler=RequestHandler) server.register_introspection_functions() server.register_function(pow) def chat_function(self): return (self) server.register_function(chat_function, 'chat') def chat_store(self): to_write = self if path.exists(PATH): chat_st2 = open(PATH,'w') history = chat_st2 chat_st2.seek(0) chat_st2.write(str(to_write)) chat_st2.close() chat_st2 = open(PATH,'r') print (chat_st2) else: open(PATH,'w') chat_st2 = open(PATH,'w') chat_st2.write(str(to_write)) chat_st2.close() server.register_function(chat_store, 'store') print ('Starting your XMLRPC Server...') print ('Press Ctrl+C to exit') server.serve_forever() if KeyboardInterrupt: exit() …

Member Avatar
Member Avatar
+0 forum 1

Is it possible (without using any external modules) to make two computers, or Python programs communicate through an Ethernet cable? E.g. Sending messages, numbers, etc. And if so, how?

Member Avatar
Member Avatar
+0 forum 3

How do you make Python set an str from a file? For example, my file would contain these pieces of text: username=Eugene password=eugene How do I get Python to return this? >>> print(username) Eugene >>> print(password) eugene Any help is deeply appreciated. Thanks!

Member Avatar
Member Avatar
+0 forum 2

How do you make Python delete a specific line of text from a file? For example, delete_input = input ('> ') file = open('blahblah.$','w') #delete the variable delete_input file.delete(delete_input from file) Any form of help would be appreciated. Thanks!

Member Avatar
Member Avatar
+0 forum 1

I have a very tough problem- how do you make an icon/character move across a console screen? For example, if I press W, +++++ ++E++ +++++ Then I press D +++++ +++E+ +++++ And I want it to be like the CHOICE command in CMD- Without requiring the user to press Enter. Any help would be appreciated! Thanks!

Member Avatar
Member Avatar
+0 forum 2

How do you make Python delete a string or a number (in this case, .0) from a file? Example: #Error Fixing if '.0' in open('ship.$','r'): #Delete the '.0'

Member Avatar
Member Avatar
+0 forum 5

Guys check out http://cx6-dev.blogspot.com/ for an awesome game coded in Python. It's new but still fun. HIGHLY RECOMMENDED! PS: You'll need to have Python 3.2 or above to install/play it.

Member Avatar
+0 forum 0

I have a code for a game. money_file = open ('money.$','r').read() money_file = str(money_file) money = int(money_file) But everytime I run it, it returns an error: Traceback (most recent call last): File "C:\Users\eeo.j\Desktop\CX6 SDK\CX6 Normal\CX6.py", line 86, in <module> money = int(money_file) ValueError: invalid literal for int() with base 10: '' I need to get the money variable into an interger, but I can't. Anyone got any idea what's going on?

Member Avatar
Member Avatar
+0 forum 6

I've been working on Tkinter, and setting a message box. It worked fine, but I didn't really like the fact that the text displayed was in a small position in the window. Take a look at this code and you'll know what I mean. def About(self): text = Message(self, text=''' .:: About Python ::. Blah blah blah blah.''') text.grid(column=1, row = 5 and 4) text.pack() I don't know how to make the text 'spread out' over the entire screen. Take a look at this photo to understand it. And I'll be glad if someone could help me find a way …

Member Avatar
Member Avatar
+0 forum 3

Is there any way to host several txt files on a computer without having to dive deep into socket programming? I have a few requirements, though: * People could connect when the app is running * No inteference of Windows * Instructions on how to create a client side software * Python 3.2 Coding Although the requirements are demanding, any form of help is appreciated. :)

Member Avatar
Member Avatar
+0 forum 6

The End.