Author Topic: Is there a way to call a Torque function using Python and vice versa?  (Read 2197 times)

Python as far as I know doesn't have functions such as GetWord() or GetSubStr(), so I was wondering if I could call torque functions in IDLE, and Python functions in Blockland somehow.

you can probably do it by making a local server in python and a tcpobject in blockland connect and having them communicate

You'll need Django, code in bit bucket and a continuous integration server for this.

Python as far as I know doesn't have functions such as GetWord() or GetSubStr()

>>> foo = 'hello world'
>>> foo[0:5]
'hello'
>>> foo[0:2]
'he'
>>> foo[3]
'l'
>>> bar = foo.split(' ')
>>> bar
['hello', 'world']
>>> bar[0]
'hello'
>>> bar[1]
'world'
>>> bar[1] = 'blockland'
>>> ' '.join(bar)
'hello blockland'

Python as far as I know doesn't have functions such as GetWord() or GetSubStr(), so I was wondering if I could call torque functions in IDLE, and Python functions in Blockland somehow.


########################
#Sticks and Stones Lang#
#By Brian Smith        #
#Version 1 Build 1     #
########################
########
#SubStr#
########
def getSubStr(string,start,end):
   return string[start:end]
def strLen(string):
   return len(string)
######################
#Basic Word Functions#
######################
def firstWord(string):
   return string.split(" ")[0]
def restWords(string):
   return string.split(" ")[1:]
def lastWord(string):
   return string.split()[-1]
def getWordCount(string):
   words = string.split()
   return words.len()
def getWord(string,num)
   words = string.split('')
   if num > words.len():
      return -1
   else:
      return words[num]

#######################
#Basic Field Functions#
#######################
def getFieldCount(string):
   fields = string.split('\t')
   return fields.len()
def getField(string,num):
   fields = string.split('\t')
   if num > fields.len():
      return -1
   else:
      return fields[num]

######################
#Basic Line Functions#
######################
def getLineCount(string):
   lines = string.split('\n')
   return lines.len()
def getLine(string,num):
   lines = string.split('\n')
   if num > lines.len():
      return -1
   else:
      return lines[num]


:)

You'll need Django, code in bit bucket and a continuous integration server for this.

You'll need Django, code in bit bucket and a continuous integration server for this.

Why the hell would you need Django or BitBucket for this?


Why the hell are you creating functions which have natural language constructs already anyway?

I wanna know the answers to those questions too...

I wanna know the answers to those questions too...

Which exact questions?

Why the hell would you need Django or BitBucket for this?

Django obviously because everyone who writes Python uses it basically - it's just how it's done these days. I'm sure if you learned a bit more about python you'd probably realise this.

BitBucket to keep the code in because lets face it, where else do you keep python code? Also open source is the future!

Which exact questions?
yours
Django obviously because everyone who writes Python uses it basically - it's just how it's done these days. I'm sure if you learned a bit more about python you'd probably realise this.

BitBucket to keep the code in because lets face it, where else do you keep python code? Also open source is the future!
..... this almost seems like trolling..?

not sure how a web development framework is going to help op, but if you say so i guess

Django obviously because everyone who writes Python uses it basically - it's just how it's done these days. I'm sure if you learned a bit more about python you'd probably realise this.

Except OP most likely isn't looking for a web-based solution. Twisted?

BitBucket to keep the code in because lets face it, where else do you keep python code?

Developing in a repository system isn't necessary.

Adam you should probably wait for DontCare4Free to get here, these jokers clearly don't know anything about Python.

Adam you should probably wait for DontCare4Free to get here, these jokers clearly don't know anything about Python.
Hi.

Why the hell are you creating functions which have natural language constructs already anyway?
Probably as a quick dictionary ("this" is how you do "that" the Python way).

Django obviously because everyone who writes Python uses it basically - it's just how it's done these days. I'm sure if you learned a bit more about python you'd probably realise this.
Django is a fairly popular web development framework for Python. Python isn't a single-framework language like Ruby (while Ruby can be used on it's own or with another framework, let's be honest here, when was the last time you saw anyone do it?). Django in itself contributes nothing to general-purpose development and only helps with website-specific tasks.

BitBucket to keep the code in because lets face it, where else do you keep python code? Also open source is the future!
Bitbucket is not bound to OSS/"publicness" and is also fully optional. There are several alternatives to choose from, including self-hosting and nothing such at all.

Python as far as I know doesn't have functions such as GetWord() or GetSubStr(), so I was wondering if I could call torque functions in IDLE,
It's a bad idea. Instead, while learning, you might want to look it up in Brian's answer (although I've changed a few things to fix syntax errors, etc).
Code: [Select]
########################
#Sticks and Stones Lang
#By Brian Smith
#Version 1 Build 1
########################
########################
#SubStr
########################
def getSubStr(string,start,end):
return string[start:end]
def strLen(string):
return len(string)
########################
#Basic Word Functions
########################
def firstWord(string):
return string.split(" ")[0]
def restWords(string):
return string.split(" ")[1:]
def lastWord(string):
return string.split(" ")[-1]
def getWordCount(string):
return len(string.split(" "))
def getWord(string, num):
words = string.split(" ")
if num > len(words):
return None
else:
return words[num]

########################
#Basic Field Functions
########################
def getFieldCount(string):
fields = string.split('\t')
return fields.len()
def getField(string,num):
fields = string.split('\t')
if num > fields.len():
return None
else:
return fields[num]

########################
#Basic Line Functions
########################
def getLineCount(string):
lines = string.split('\n')
return lines.len()
def getLine(string,num):
lines = string.split('\n')
if num > lines.len():
return None
else:
return lines[num]

[/tt]
:)

and Python functions in Blockland somehow.
The simplest way to do with would probably be with the (bundled) SocketServer microframework (more specifically, look into TCPServer and StreamRequestHandler) on the Python side while using regular TCPObjects on the Torque side. One issue, however, is that network IO is asynchroneous/non-blocking in Torque (meaning that the function returns before you have a response) which you'll have to adapt your code for.



Anything else?
« Last Edit: June 12, 2012, 07:39:16 AM by DontCare4Free »

Lol you all got baited so badly in this topic.