I thought it'd be better to use JSON or YAML to store lists of dictionaries (a documents-based database) and then create a nice little front-end to wrap the code up, since people claim that pickle is insecure against "maliculously constructed data".

I'm just worried that it wouldn't be happy with single-character tokens, because my syntax has some funny and weird stuff like ~++ $--#.

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!

Thanks dude! Though the code is barely understandable. I do not understand why you'd have to create the START, END, DATA, EMPTY variables.

The problem is that the '"name":{content}' part would be invalid. I need a way to check whether it's a tree of tags or just a tag on it's own. And the content that's parsed would be dynamic.

No it wouldn't, because sometimes the configuration options are deeply nested within one another, i.e.:

[options]
  [user]
    [name]John Doe[/name]
    [age]Age[/age]
  [/user]
  [packages]
    [pkg]
      [version]1.2[/version]
      [summary]Something[/summary]
      [author]John Doe[/author]
    [/pkg]
  [/packages]
[/options]

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 going in one branch
                self.rlevel += 1
                self.generate_di(item[key])
                # we have finished parsing that branch
                self.rlevel -= 1
                self.puts(self.endtag % key)
            else:
                self.puts(self.strtag % key + str(item[key]) + self.endtag % key)

Which takes in a dictionary, say {"deltas":{"key":"data", "key2":"data"}} and puts this into the stream:

[deltas]
  [key]data[/key]
  [key2]data[/key2]
[/deltas]

As you can see this is very XML-like but eliminates the complex tree and attributes arguments. Any help would be appreciated!

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 work

It seems to block at the while True loop found in the first snippet. How can I solve this problem?

You can always use the threading module for scheduling such functions trivially. I.e.

def worker(self, name): 
# check if we need to exit
    while not self._exitflag:
        time.sleep(self._nap_time)
        self._threadLock.acquire()

        if self._need_to_do_job:
            # perform jobs
            pass

        self._threadLock.release()

Though when you .join() the function, you will need to wait for the time specified in your self._nap_time variable.

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]?

Alright thanks. Gave me a ton of help there.

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)?

I've started writing a 2d platformer game some days ago, and I'm really enthusiastic about it, but I already failed to live up to my own expectations: I just cannot possibly think of a way I could make my character jump. I used the MVC desing is why, and now I'm looking for some help. I made a thread at gamedev.net, which contains some code. I appreciate the reading, and any help you can give!

I don't know what kind of module you're using, but I know a way. You can print (or show) several whitespaces or an image/sprite below the character's feet. Then elevate the character to your desired height. Hope that helps.

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')

I need help with my facebook page it wont load and my media player wont let me play it

This is not considered 'Software Development'. And you can't 'play' a Facebook page.

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!

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()

But for some reason it keeps getting errors.

Can you provide me with an example? I'm too confused when reading those tutorials online.

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?

Thanks! Can't wait to try that out

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!

@Gribouillis: How do I add a third str into the input?

For example

def do_ADD(self, line, third_str):

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!

Mind you, this will only work if the enter value is exactly 'ECHO', all caps. THis probably isn't what you wanted, but I'll leave it to you to make any corrections of that sort.

Thanks, but it always seems to return something like this:

> ECHO haha
haha >

I want it to be like this:

> ECHO Haha
Haha
> 

What do I do to make it happen?

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?

But how about the movement part? Like how do I apply this...

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!

Thanks! I'll see how I could apply that to my game.

From your other posts, I can see you are making a game. Are you trying to develop a save system or game data system? There may be better alternatives than the manipulations you are attempting. You should also read a good tutorial on file steams.

Yes, I am trying to make a game. But I couldn't develop a save system- so I used this method.

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'