带字符串的while循环仅运行一次

时间:2020-02-04 00:11:10

标签: python python-3.x while-loop

我很难弄清楚这段代码出了什么问题。有人可以告诉我while循环有什么问题吗?它只会运行一次。

const path = require('path');
const multer = require('multer');
const crypto = require('crypto');
const GridFsStorage = require('multer-gridfs-storage');

// Create storage engine
const initStorage = (conn, bucketName) => new GridFsStorage({
  db: conn,
  file: (req, file) => {
    return new Promise((resolve, reject) => {
      crypto.randomBytes(16, (err, buf) => {
        if (err) {
          return reject(err);
        }
        const filename = buf.toString('hex') + path.extname(file.originalname);
        const fileInfo = {
          filename: filename,
          bucketName: bucketName
        };
        resolve(fileInfo);
      });
    });
  }
});


const initUpload = (storage) => multer({
  storage: storage,
  fileFilter: function (req, file, callback) {
    const ext = path.extname(file.originalname);
    if (ext !== '.png' && ext !== '.jpg' && ext !== '.gif' && ext !== '.jpeg') {
      return callback(new Error('Only images are allowed'))
    }
    callback(null, true)
  }
});

module.exports = { initStorage, initUpload };

2 个答案:

答案 0 :(得分:0)

您需要在()通话后添加lower。您实际上从未真正将函数调用为小写的i

while i.lower() == "i":

i.lower
<built-in method lower of str object at 0x0000018E4AC5A0F0>

i.lower == 'i'
False

i.lower()
'i'

i.lower() == 'i'
True

答案 1 :(得分:0)

这可行,但是您只需要输入i,而不是I。

i= input("Please enter I to report or enter to exit. ")
while i == "i":
    if i == "i":
        print("in loop")
        i = input("Please enter I to report  or enter to exit. ")
if i != "i" :
    print("done")