2017-11-22 3 views
0
def add_div(filename, caption): 

    test = str(filename) 
    return ('<div><img src=' + test + '><br><p>' + caption + '</p></div>') 


def add_body(image_dict, s, order = None): 
    '''(dict of {str:list of str}, str, list) -> str 

    If the third parameter is passed, then the filenames 
    included in the body should only be those in the list and should be added 
    in the same order as they are listed in the list. ''' 
    new = '' 
    s = '<html><head></head>' 

    while order is None: 
     for (key, value) in image_dict.items(): 
      new += add_div(str(key), str(value[2])) 
     return (s + '<body><div id="slideshow">' + new + '</body>'+ '</html>') 

出力は次のようになります。 enter image description here文字列内の引用符を置く

私は言葉画像/ skater.jpgを囲む引用符を得るのですか?

これはあなたがこのように連結されていることを文字列に引用符を含めることができるファイルは enter image description here

答えて

0

次のようになります。

def add_div(filename, caption): 

    test = str(filename) 
    return ('<div><img src="' + test + '"><br><p>' + caption + '</p></div>') 
0

使用string定義のためquotationの1種類と含まれているもののもう1つは

>>> "bob said: 'hello'" 
"bob said: 'hello'" 
>>> "I said 'yo bob, how u doing?' in reply" 
"I said 'yo bob, how u doing?' in reply" 

だからあなたの問題を解決するには、ちょうどに最初functionreturn文を変更します。最終的なものとして、return文の括弧は次のように必要とされていないことを

return ('<div><img src="' + test + '><br><p>'" + caption + '</p></div>') 

注意returnは、functionまたはmethodではありません。

2

次の2つの別々のオプションがあります。

1)を使用し、二重引用符

print("Hey that's pretty cool!") 

print('Hey that\'s pretty cool!') 
+1

私が入力している間、あなたはエスケープで私を打ち負かしました... –

0

良い答えを単一引用符をエスケープするが、別の方法が脱出することです一重引用符または二重引用符で\

例:

# this is the same as 
# s = "'" 
s = '\'' 
print(s) 

#this is the same as 
# s = '"' 
s = "\"" 
print(s) 
関連する問題