如何解决Python中嵌套列表的排列
想象一个列表列表,像这样:
const discord = require('discord.js');
require('dotenv').config();
const client = new discord.Client();
client.login(process.env.BOT_TOKEN);
const ms = require('ms');
const prefix = '-';
const fs = require('fs');
client.commands = new discord.Collection();
const commandFiles = fs.readdirsync('./commands/').filter(file => file.endsWith('.js'))
for(const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.name,command);
}
client.once('ready',() => {
console.log('Dahj is online!');
});
client.on('message',async message =>{
if(message.author.bot) return;
if(message.content.toLowerCase() === '?listen') {
message.channel.send('bot is collecting messages Now...');
let filter = m => !m.author.bot;
let collector = new discord.MessageCollector(message.channel,filter);
let destination = client.channels.get('767508773966315550');
collector.on('collect',(m,col) => {
console.log("Collected message: " + m.content);
if(destination) {
if(m.content.toLowerCase() === '?stop' && (message.author.id === m.author.id)) {
console.log("Stopping collector.");
collector.stop();
}
else {
let embed = new discord.RichEmbed()
.setTitle("New Message")
.setDescription(m.content)
.setTimestamp()
.setAuthor(m.author.tag,m.author.displayAvatarURL)
.setColor('#FFAB32')
destination.send(embed);
}
}
});
collector.on('end',collected => {
console.log("Messages collected: " + collected.size);
});
}
if(message.content.toLowerCase() === '?listen2') {
message.channel.send("Enter your name");
let filter = m => m.author.id === message.author.id;
try {
let msg = await message.channel.awaitMessages(filter,{ maxMatches: 1,time: '10000',errors: ['time'] });
message.channel.send("Your name " + msg.first().content);
}
catch(ex) {
message.channel.send("You did not specify a name on time.");
}
}
});
My error is:
(node:15556) UnhandledPromiseRejectionWarning: ReferenceError: discord is not defined
at Client.<anonymous> (C:\Users\malibukid71\Documents\Dahj2\main.js:34:25)
at Client.emit (events.js:315:20)
at MessageCreateAction.handle (C:\Users\malibukid71\Documents\Dahj2\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\malibukid71\Documents\Dahj2\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\malibukid71\Documents\Dahj2\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Users\malibukid71\Documents\Dahj2\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\malibukid71\Documents\Dahj2\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\malibukid71\Documents\Dahj2\node_modules\ws\lib\event-target.js:125:16)
at WebSocket.emit (events.js:315:20)
at Receiver.receiverOnMessage (C:\Users\malibukid71\Documents\Dahj2\node_modules\ws\lib\websocket.js:797:20)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:15556) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block,or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection,use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:15556) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future,promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
除了更长。我需要一个脚本为任意长度的列表生成排列,该列表包含少量单词集,也包含任意长度。
因此,在这种情况下:
import platform
from os import getcwd
from selenium import webdriver
if (platform.system() == 'Windows'):
driver = webdriver.PhantomJS(executable_path=getcwd() + "\phantomjs")
if (platform.system() == 'Darwin'):
driver = webdriver.PhantomJS(executable_path=getcwd() + "/phantomjs")
我无法使用itertools进行管理。有什么建议吗?
解决方法
从itertools中尝试permutations()
:
from itertools import permutations
x=[['foo','bar'],['baz'],['xyz']]
for y in permutations(x):
print(y)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。