小编Pau*_*can的帖子

Python子/父类,子类返回字符串两次?

简单的问题,对你们中的一个人来说可能非常明显,但我不确定为什么会这样.所以这里是我制作的三个python文件.

主要Char类:

class Character():
    """
    This is the main parents class for creation of
    characters, be they player, NPC or monsters they
    shall all share common traits
    """

    def __init__(self, name, health, defense):
        """Constructor for Character"""
        self.name = name
        self.health = health
        self.defense = defense
Run Code Online (Sandbox Code Playgroud)

玩家类:

from character import *

class Player(Character):
    """
    The player class is where heros are made
    They inherit common traits from the Character class
    """

    def __init__(self, name, health, defense, str, int):
        Character.__init__(self, name, health, …
Run Code Online (Sandbox Code Playgroud)

python string parent-child

3
推荐指数
1
解决办法
1万
查看次数

PHP 中如果值存在则 MySQL 更新,如果不存在则插入?

$sql_career = "REPLACE INTO career
         (id, battletag, lastHeroPlayed, lastUpdated, monsters, elites, hardcoreMonsters, barbarian, crusader, demonhunter, monk, witchdoctor, wizard, paragonLevel, paragonLevelHardcore)
         VALUES
         ('', '$battletag', '$lastHeroPlayed', '$lastUpdated', '$monsters', '$elites', '$hardcoreMonsters', '$barbarian', '$crusader', '$demonhunter', '$monk', '$witchdoctor', '$wizard', '$paragonLevel', '$paragonLevelHardcore')";
Run Code Online (Sandbox Code Playgroud)

ID自动递增。 battletag是独特的。

其他一切都会随着时间而改变。因此,如果条目已经存在,我想替换或更新条目battletag而不创建新的id。如果它不存在,我希望它创建一个新条目,让id该唯一的自动增量battletag


这可以解决一个问题:

 $sql_career = "
    insert INTO career
      (id, battletag, lastHeroPlayed)
    VALUES
      (NULL, '$battletag', $lastHeroPlayed)
    on duplicate key
      update lastHeroPlayed=$lastHeroPlayed;
 ";
Run Code Online (Sandbox Code Playgroud)

例如,如果我加载两个唯一的行,则每个行的 ID 自动递增到 1,然后递增到 2。然后,如果我加载的行具有现有行之一的唯一键的重复项(然后按预期更新),这实际上会触发自动增量。因此,如果我添加第三个唯一行,其编号将是 4 而不是 3。

我怎样才能解决这个问题?

php mysql

2
推荐指数
1
解决办法
1596
查看次数

Zipfiles的Python问题

免责声明:编码新手

C:\Python27\python.exe C:/Users/Evolution/PycharmProjects/MCMODVERSION/stuff/main.py
<open file 'C:\\Users\\Evolution\\Desktop\\mods\\AT_StalkerCreepers_1.6.4.jar', mode 'r' at 0x026F6A18>
Traceback (most recent call last):
True
<zipfile.ZipFile object at 0x02736EB0>
  File "C:/Users/Evolution/PycharmProjects/MCMODVERSION/stuff/main.py", line 80, in <module>
<open file 'C:\\Users\\Evolution\\Desktop\\mods\\BC_AdditionalPipes2.6.0-BC4.2.1.jar', mode 'r' at 0x026F6AC8>
    o = t.getdirList()
True
  File "C:/Users/Evolution/PycharmProjects/MCMODVERSION/stuff/main.py", line 36, in getdirList
    self.getModinfo(os.path.join(p, o[n]), 'name')
  File "C:/Users/Evolution/PycharmProjects/MCMODVERSION/stuff/main.py", line 46, in getModinfo
    y = zipfile.ZipFile(x)
  File "C:\Python27\lib\zipfile.py", line 766, in __init__
    self._RealGetContents()
  File "C:\Python27\lib\zipfile.py", line 832, in _RealGetContents
    raise BadZipfile("Truncated central directory")
zipfile.BadZipfile: Truncated central directory

Process finished with …
Run Code Online (Sandbox Code Playgroud)

python zip jar

1
推荐指数
1
解决办法
784
查看次数

标签 统计

python ×2

jar ×1

mysql ×1

parent-child ×1

php ×1

string ×1

zip ×1