我目前的情况是使用名为pygame的库在python中制作游戏.我有一个名为getTile()的方法,每次玩家移动时都返回一个tile.lvlDict弥补了这个世界.
def getTile(self, pos):
x = pos[0]
y = pos[1]
return self.lvlDict[x,y].kind
Run Code Online (Sandbox Code Playgroud)
而我正在考虑改变它
def getTile(self, pos):
try:
x = pos[0]
y = pos[1]
return self.lvlDict[x,y].kind
except KeyError:
return None
Run Code Online (Sandbox Code Playgroud)
如果它是无,那么会有什么解释.可能只是回到以前的位置.这本身就是坏的还是可以接受的?即使这仅仅是一个意见问题,我想知道人们对它的看法.
我正在尝试使用 pyinstaller 来构建我一直在开发的程序,但之后我遇到了二进制文件的问题。这是我的程序。
首先我运行了pyinstall test.py然后我使用运行了二进制文件,./dist/main/test但是我得到了这个错误,而正常运行脚本时我没有得到这个错误(例如python3 test.py)。
Traceback (most recent call last):
File "PIL/ImageTk.py", line 181, in paste
_tkinter.TclError: invalid command name "PyImagingPhoto"
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "magic-collection-tracker/test.py", line 22, in <module>
File "magic-collection-tracker/test.py", line 11, in main
File "PIL/ImageTk.py", line 120, in __init__
File "PIL/ImageTk.py", line 185, in paste
ModuleNotFoundError: No module named 'PIL._tkinter_finder'
Run Code Online (Sandbox Code Playgroud)
这是重现该问题的最小示例。
from PIL import ImageTk
import PIL.Image
from tkinter …Run Code Online (Sandbox Code Playgroud) 使用看起来像这样的JSON文件,
{
"dict": {"key": "value"}
}
Run Code Online (Sandbox Code Playgroud)
我怎么能在Unity中制作一个名为"dict"的字典,看起来像这个{"key":"value"}?
这是我的课.
[Serializable]
public class MyJson
{
public Dictionary<string,string> dict;
}
Run Code Online (Sandbox Code Playgroud)
我不知道为什么,但是当我尝试使用这个类和JsonUnility.FromJson()方法时,它似乎没有将dict更改为我期望的字典.相反,它只是空.
编辑:我已经看到在Unity文档中它说"字典不受支持"所以是否有一些方便的方法来轻松创建字典或者我是否必须将自己与数据拼凑在一起?
这是一个潜在的JSON.这种问题进入我遇到的另一个问题,虽然我用python创建了JSON,这意味着我可以在我的字典中使用不同的值类型,但这对C#不起作用所以现在它只是字符串而且我会稍后想出一些东西.(可能通过将其全部列出,那么只有字符串的那些只有1个元素)
{
"pages": [
{
"files": "[null, null, null, null]",
"imagepath": "C:/Users/Jeff/Pictures/location_sharing.png",
"pageNum": "0",
"polygons": "[[[122, 184], [178, 180], [174, 159], [126, 158]], [[191, 157], [194, 185], [241, 183], [246, 154]], [[334, 219], [323, 236], [323, 247], [338, 259], [358, 259], [364, 236], [356, 221], [344, 215]], [[512, 221], [503, 235], [508, 256], [518, 267], [538, 260], [548, 250], [541, …Run Code Online (Sandbox Code Playgroud)