[ / / / / / / / / ] [ b / news+ / boards ] [ operate / meta ] [ ]

/gentoo/ - Technology

Install gentoo.

Catalog

Name
Email
Subject
Comment *
File
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Options
Password (For file and post deletion.)

Allowed file types: jpg, jpeg, gif, png, webm, mp4
Max filesize is 8 MB.
Max image dimensions are 10000 x 10000.
You may upload 1 per post.


File: 1411688696260.jpg (29.96 KB, 355x444, 355:444, a.jpg)

 No.311

Hello /gentoo/,
Intermediate python user here,
looking for a challenge, someone throw me some inspiration?
also, rate my source code-
https://github.com/BenevolentCryptopunk/textKind

 No.326

>>311
Try you hand at making a KCS Converter?
May not be your thing, But its fun to play with.

http://en.wikipedia.org/wiki/Kansas_City_standard

 No.331

>>311

SUGGESTIONS

learn sockets, expand your (MudOS inspired?) text game into a MUD

learn some natural language processing and improve the command parser. python's NLTK would be a good starting point. http://www.nltk.org/

SOURCE CODE RATING

1. your code needs more try/catch. for example, I can't smoke the egg:

 >smoke wierd_egg
Traceback (most recent call last):
File "__init__.py", line 67, in <module>
playerInput.inputHandle()
File "/home/dicks/textKind/playerInput.py", line 39, in inputHandle
passThrough(command, inp, storeError)
File "/home/dicks/textKind/playerInput.py", line 51, in passThrough
consume(inp[1:])
File "/home/dicks/textKind/playerInput.py", line 100, in consume
player.user.removeItem(eval('element.' + array[i]))
File "/home/dicks/textKind/player.py", line 127, in removeItem
self.inventory.remove(thing)
ValueError: list.remove(x): x not in list


2.
> 2014
> using eval

imo rewrite elements to use a dictionary instead of relying on eval('element.'+id+'.property')

3. you have code like this in a few places

    for i in range(len(array)):
if array[i] in element.allElements:


nigger are you serious. consider the following:

    for item in array:
if item in element.allElements:


in general you might like to look up some of the python protocol stuff. shit like defining __getitem__ and __iter__ methods on classes. you could use such methods to trim complexity in a few places.

(also, in the bit I quoted, where you have deep nested if/else blocks, I would personally use try/catch and have functions that throw NoSuchThingException etc)

4.

you could use list comprehensions to write tighter code in a few places, e.g.:

    for i in player.user.inventory:
if i.type == 'weapon':
weapArray.append(i.name)


becomes

    weapArray = [i.name for i in player.user.inventory if i.type == 'weapon']
weapArray.append(i.name)


tl;dr it looks like you already know a different programming language and are trying to write python using old habits from it. I don't like the idea that code should be 'Pythonic' because it sounds weird and cult-like, but you might benefit from reading up on it for comparison's sake if nothing else. keep studying and you'll be a pro in no time.

 No.332

>>331

typo: scratch
weapArray.append(i.name)
from that last section.

the shit I would do for a preview button here

 No.356

>>331
>I can't smoke the egg
Shit game. Wouldn't play.

 No.360

>>311
>>311
OpenCL accelerated fizzbuz



Delete Post [ ]
[]
[Return][Go to top][Catalog]
[ / / / / / / / / ] [ b / news+ / boards ] [ operate / meta ] [ ]