Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

283
Views
JavaScript a Python (usando JS2PY)

Tengo una cosa de cálculo de semillas que usa JavaScript (Funciona correctamente). Estoy intentando convertirlo a Python (para un proyecto más detallado) usando la biblioteca JS2PY.

Mi código:

 import js2py hasCode = js2py.eval_js('function hashCode(s) {let h = 0; for (let i = 0; i < s.length; i++) {h = (Math.imul(31, h) + s.charCodeAt(i)) | 0;} return h;}') getSeed = js2py.eval_js('function getSeed(s) {let x = BigInt(hashCode(s)); if (/^[\-\+0-9]*$/.test(s)) {try {let y = BigInt(s); if (BigInt.asIntN(64, y) !== y) {throw RangeError();} x = y;} catch (err) {}} return { high: x >> 32n, low: BigInt.asIntN(32, x) };}') output = js2py.eval_js('function output() {let seed = -734744700160476640; print("Copy this output - " + seed.high, seed.low);}') output()

Si usa esto, digamos, en un archivo HTML, el JavaScript producirá un "Alto" y un "Bajo" de la entrada inicial (aquí está -734744700160476640, pero permitiría a los usuarios ingresar su propia semilla).

El registro de comandos explica que hay errores de sintaxis en los archivos que supongo que son de la biblioteca. Probablemente noten que soy un poco inexperto, así que si es mi propio código el que está roto, díganlo. No sé si JS2PY está desactualizado o si hay mejores opciones por ahí. No pude encontrar ninguno yo mismo.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!